## Replication Code
## Accountability for the Local Economy at All Levels of Government in United States Elections
## Justin de Benedictis-Kessner and Christopher Warshaw
## This code file creates all figures (except maps)


## Preamble:
library(tidyverse)
library(lfe)

load("econ_counties_cities_analysis.Rdata")


#---------------------------------#
#### Appendix A: Data coverage ####
#---------------------------------#

## for elections:
data_analysis %>%
	group_by(!is.na(partisanship_federal)) %>%
	summarize(min=min(year), # 1968
						max=max(year)) # 2018

data_analysis %>%
	group_by(!is.na(mayor_demshare)) %>%
	summarize(min=min(year),
						max=max(year)) # 2012

data_analysis %>%
	group_by(!is.na(countyleg_avg_demshare)) %>%
	summarize(min=min(year),
						max=max(year)) # 2016



summary_tab <- data_analysis %>%
	filter(population_2010 > 20000) %>%
	group_by(year) %>%
	summarize(
		pres = sum(!is.na(pres_demshare)),
		senate = sum(!is.na(sen_demshare)),
		house = sum(!is.na(house_demshare)),
		gov = sum(!is.na(gov_demshare)),
		stateexec = sum(!is.na(stateoffice_demshare)),
		sldl = sum(!is.na(sldl_demshare)),
		county = sum(!is.na(countyleg_avg_demshare)),
		mayor = sum(!is.na(mayor_demshare)))


summary_tab2 <- summary_tab %>%
	dplyr::select(year,pres,senate,house,gov,stateexec,sldl,county,mayor) %>%
	tidyr::gather(pres,senate,house,gov,stateexec,sldl,county,mayor,key="race",value="n")


#---------------------------------#
#### Figure A-1: Data coverage ####
#---------------------------------#

summary_tab2 <- summary_tab2 %>%
	mutate(race2 = recode(race, 
												"pres" = "President","senate" = "Senate","house"="House",
												"gov" = "Governor","stateexec" = "Downballot\nState\nOffices","sldl" = "State\nHouse",
												"county" = "County\nLegislature","mayor" = "Mayor"),
				 race2 = factor(race2,levels = c("President","Senate","House","Governor","Downballot\nState\nOffices","State\nHouse","County\nLegislature","Mayor"),ordered=T))

elecs_coverage <- ggplot(summary_tab2) + 
	geom_histogram(aes(x=year,y=n),stat="identity",fill="cornflowerblue") + 
	facet_wrap(~race2,ncol=1,scales = "free_y",strip.position="right") + 
	scale_x_continuous("Year",breaks = seq(1970,2018,4)) + 
	scale_y_continuous("") + 
	theme_bw() + 
	theme(strip.text = element_text(size=10)) + 
	theme(axis.title.x = element_text(size=15),axis.text.x = element_text(size=10))

ggsave("Figures/coverage_elecs.pdf",elecs_coverage,height=7,width=11)


#--------------------------------#
#### Appendix C: Voter Myopia ####
#--------------------------------#

lag.new <- function(x, n = 1L, along_with){
  index <- match(along_with - n, along_with, incomparable = NA)
  out <- x[index]
  attributes(out) <- attributes(x)
  out
}

lead.new <- function(x, n = 1L, along_with){
  index <- match(along_with + n, along_with, incomparable = NA)
  out <- x[index]
  attributes(out) <- attributes(x)
  out
}

data_analysis <- group_by(data_analysis, fips) %>%
	mutate( 
		wages_perworker_real_log=log(wages_perworker_real+1)*100,
		wages_perworker_real_delta_lag3 =lag.new(wages_perworker_real_delta,along_with=year,n=3),
		wages_perworker_real_delta_lag2 =lag.new(wages_perworker_real_delta,along_with=year,n=2),
		wages_perworker_real_delta_lag1 =lag.new(wages_perworker_real_delta,along_with=year,n=1),
		wages_perworker_real_lag4 =lag.new(wages_perworker_real_log,along_with=year,n=4),
		wages_perworker_real_lag3 =lag.new(wages_perworker_real_log,along_with=year,n=3),
		wages_perworker_real_lag2 =lag.new(wages_perworker_real_log,along_with=year,n=2),
		wages_perworker_real_lag1 =lag.new(wages_perworker_real_log,along_with=year,n=1),
		wages_perworker_real_delta_fullterm = wages_perworker_real_log - wages_perworker_real_lag4,
		wages_perworker_real_delta_lead1 =lead.new(wages_perworker_real_delta,along_with=year,n=1),
		wages_perworker_real_delta_lead2 =lead.new(wages_perworker_real_delta,along_with=year,n=2),
		wages_perworker_real_delta_lead3 =lead.new(wages_perworker_real_delta,along_with=year,n=3),
		wages_perworker_real_delta_lead4 =lead.new(wages_perworker_real_delta,along_with=year,n=4),
		wages_perworker_real_delta_lead5 =lead.new(wages_perworker_real_delta,along_with=year,n=5),
		wages_perworker_real_lead1 =lead.new(wages_perworker_real_log,along_with=year,n=1),
		wages_perworker_real_lead2 =lead.new(wages_perworker_real_log,along_with=year,n=2),
		wages_perworker_real_lead3 =lead.new(wages_perworker_real_log,along_with=year,n=3),
		wages_perworker_real_lead4 =lead.new(wages_perworker_real_log,along_with=year,n=4),
		wages_perworker_real_lead5 =lead.new(wages_perworker_real_log,along_with=year,n=5),
		partisanship_federal_delta_lagged =lag.new(partisanship_federal_delta,along_with=year,n=2),
		partisanship_federal_lagged =lag.new(partisanship_federal,along_with=year,n=2)
		
	)
federal_electoral_cycle <- felm(partisanship_federal_delta ~ wages_perworker_real_delta*pres_dem_control + 
																	wages_perworker_real_delta_lag1*pres_dem_control + 
																	wages_perworker_real_delta_lag2*pres_dem_control +
																	wages_perworker_real_delta_lag3*pres_dem_control | fips + state_year |0| fips, 
																data=data_analysis[data_analysis$population_2010 > 20000,])
state_electoral_cycle <- felm(partisanship_state_delta ~ wages_perworker_real_delta*pres_dem_control +
																wages_perworker_real_delta_lag1*pres_dem_control +
																wages_perworker_real_delta_lag2*pres_dem_control +
																wages_perworker_real_delta_lag3*pres_dem_control | fips + state_year |0| fips,
															data=data_analysis[data_analysis$population_2010 > 20000,])


summary(federal_electoral_cycle)
summary(state_electoral_cycle)

federal_fullterm <- felm(partisanship_federal_delta ~ wages_perworker_real_delta_fullterm*pres_dem_control 
                         | fips + state_year |0| fips, 
                         data=data_analysis[data_analysis$population_2010 > 20000,])
summary(federal_fullterm) # sig neg effect under Rep control, pos sig intx


#-----------------------------------------------#
#### Figure C-3: Myopia in Federal Elections ####
#-----------------------------------------------#

coefs_for_plot <- data.frame(
	group = c("Election Year","Election Year","Election Year","Election Year - 1","Election Year - 1","Election Year - 1","Election Year - 2","Election Year - 2","Election Year - 2","Election Year - 3","Election Year - 3","Election Year - 3"),
	estimate = c(summary(federal_electoral_cycle)$coefficients[1,1],
							 summary(federal_electoral_cycle)$coefficients[1,1]+summary(federal_electoral_cycle)$coefficients[6,1],
							 summary(federal_electoral_cycle)$coefficients[6,1],
							 summary(federal_electoral_cycle)$coefficients[3,1],
							 summary(federal_electoral_cycle)$coefficients[3,1]+summary(federal_electoral_cycle)$coefficients[7,1],
							 summary(federal_electoral_cycle)$coefficients[7,1],
							 summary(federal_electoral_cycle)$coefficients[4,1],
							 summary(federal_electoral_cycle)$coefficients[4,1]+summary(federal_electoral_cycle)$coefficients[8,1],
							 summary(federal_electoral_cycle)$coefficients[8,1],
							 summary(federal_electoral_cycle)$coefficients[5,1],
							 summary(federal_electoral_cycle)$coefficients[5,1]+summary(federal_electoral_cycle)$coefficients[9,1],
							 summary(federal_electoral_cycle)$coefficients[9,1]
	),
	se = c(summary(federal_electoral_cycle)$coefficients[1,2],
				 sqrt(summary(federal_electoral_cycle)$coefficients[1,2]^2+summary(federal_electoral_cycle)$coefficients[6,2]^2 + 2*federal_electoral_cycle$vcv[1,6]),
				 summary(federal_electoral_cycle)$coefficients[6,2],
				 summary(federal_electoral_cycle)$coefficients[3,2],
				 sqrt(summary(federal_electoral_cycle)$coefficients[3,2]^2+summary(federal_electoral_cycle)$coefficients[7,2]^2 + 2*federal_electoral_cycle$vcv[3,7]),
				 summary(federal_electoral_cycle)$coefficients[7,2],
				 summary(federal_electoral_cycle)$coefficients[4,2],
				 sqrt(summary(federal_electoral_cycle)$coefficients[4,2]^2+summary(federal_electoral_cycle)$coefficients[8,2]^2 + 2*federal_electoral_cycle$vcv[4,8]),
				 summary(federal_electoral_cycle)$coefficients[8,2],
				 summary(federal_electoral_cycle)$coefficients[5,2],
				 sqrt(summary(federal_electoral_cycle)$coefficients[5,2]^2+summary(federal_electoral_cycle)$coefficients[9,2]^2 + 2*federal_electoral_cycle$vcv[5,9]),
				 summary(federal_electoral_cycle)$coefficients[9,2]
	)
)

coefs_for_plot$party <- factor(rep(c("Republican","Democrat","Difference"),4),levels = c("Democrat","Republican","Difference"),ordered=T)
coefs_for_plot$order <- c(4.15,4,3.85,3.15,3,2.85,2.15,2,1.85,1.15,1,0.85)

coef_plot_myopia <- ggplot(data = coefs_for_plot, aes(y = estimate, x = order,color=party)) +
	geom_errorbar(data = coefs_for_plot, lwd=1, width=0.0, aes(x = order, 
																															 ymin = estimate + qnorm(0.025)*se, 
																															 ymax = estimate + qnorm(0.975)*se,
																															 col=party)
	) +
	geom_point(size = 3.75,aes(shape=party)) + 
	geom_text(data = filter(coefs_for_plot,group=="Election Year"),
						aes(y = estimate + qnorm(0.975)*se, x=order,label=party),hjust=-0.15) + 
	scale_y_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare", limits = c(-0.2,0.4),breaks = seq(-0.2,0.4,.1)) +
	scale_x_continuous("",breaks=c(1,2,3,4),labels=c("- 3","- 2","- 1","Election Year")) +
	scale_color_manual(breaks = c("Democrat","Republican","Difference"),values=c("blue","red","black")) + 
  scale_shape_manual(values = c("Republican" = 19,"Democrat" = 17,"Difference" = 15)) + 
  geom_hline(yintercept = 0,size=.5,colour="black",linetype="dotted") +
	theme_bw() +
	coord_flip() + 
	theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black")) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=15)) + 
	theme(axis.title.x = element_text(size=20)) + 
	theme(legend.position = "none")

ggsave("Figures/myopia_coefplot.pdf",coef_plot_myopia,width=11,height=6)



#---------------------------------------------#
#### Figure C-3: Myopia in State Elections ####
#---------------------------------------------#

coefs_for_plot <- data.frame(
	group = c("Year 4","Year 4","Year 4","Year 3","Year 3","Year 3","Year 2","Year 2","Year 2","Year 1","Year 1","Year 1"),
	estimate = c(summary(state_electoral_cycle)$coefficients[1,1],
							 summary(state_electoral_cycle)$coefficients[1,1]+summary(state_electoral_cycle)$coefficients[6,1],
							 summary(state_electoral_cycle)$coefficients[6,1],
							 summary(state_electoral_cycle)$coefficients[3,1],
							 summary(state_electoral_cycle)$coefficients[3,1]+summary(state_electoral_cycle)$coefficients[7,1],
							 summary(state_electoral_cycle)$coefficients[7,1],
							 summary(state_electoral_cycle)$coefficients[4,1],
							 summary(state_electoral_cycle)$coefficients[4,1]+summary(state_electoral_cycle)$coefficients[8,1],
							 summary(state_electoral_cycle)$coefficients[8,1],
							 summary(state_electoral_cycle)$coefficients[5,1],
							 summary(state_electoral_cycle)$coefficients[5,1]+summary(state_electoral_cycle)$coefficients[9,1],
							 summary(state_electoral_cycle)$coefficients[9,1]
	),
	se = c(summary(state_electoral_cycle)$coefficients[1,2],
				 sqrt(summary(state_electoral_cycle)$coefficients[1,2]^2+summary(state_electoral_cycle)$coefficients[6,2]^2 + 2*state_electoral_cycle$vcv[1,6]),
				 summary(state_electoral_cycle)$coefficients[6,2],
				 summary(state_electoral_cycle)$coefficients[3,2],
				 sqrt(summary(state_electoral_cycle)$coefficients[3,2]^2+summary(state_electoral_cycle)$coefficients[7,2]^2 + 2*state_electoral_cycle$vcv[3,7]),
				 summary(state_electoral_cycle)$coefficients[7,2],
				 summary(state_electoral_cycle)$coefficients[4,2],
				 sqrt(summary(state_electoral_cycle)$coefficients[4,2]^2+summary(state_electoral_cycle)$coefficients[8,2]^2 + 2*state_electoral_cycle$vcv[4,8]),
				 summary(state_electoral_cycle)$coefficients[8,2],
				 summary(state_electoral_cycle)$coefficients[5,2],
				 sqrt(summary(state_electoral_cycle)$coefficients[5,2]^2+summary(state_electoral_cycle)$coefficients[9,2]^2 + 2*state_electoral_cycle$vcv[5,9]),
				 summary(state_electoral_cycle)$coefficients[9,2]
	)
)

coefs_for_plot$party <- factor(rep(c("Republican","Democrat","Difference"),4),levels = c("Democrat","Republican","Difference"),ordered=T)
coefs_for_plot$order <- c(4.15,4,3.85,3.15,3,2.85,2.15,2,1.85,1.15,1,0.85)

coef_plot_myopia_state <- ggplot(data = coefs_for_plot, aes(y = estimate, x = order,color=party,shape=party)) +
	geom_errorbar(data = coefs_for_plot, lwd=1, width=0.0, aes(x = order, 
																														 ymin = estimate + qnorm(0.025)*se, 
																														 ymax = estimate + qnorm(0.975)*se,
																														 col=party)
	) +
	geom_point(size = 3.75) + 
	geom_text(data = filter(coefs_for_plot,group=="Year 4"),
						aes(y = estimate + qnorm(0.975)*se, x=order,label=party),hjust=-0.15) + 
  scale_y_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare", limits = c(-0.25,0.45),breaks = round(seq(-.3,.5,.1),2)) +
  scale_x_continuous("",breaks=c(1,2,3,4),labels=c("- 3","- 2","- 1","Election Year")) +
  scale_color_manual(breaks = c("Democrat","Republican","Difference"),values=c("blue","red","black")) + 
  scale_shape_manual(values = c("Republican" = 19,"Democrat" = 17,"Difference" = 15)) + 
  geom_hline(yintercept = 0,size=.5,colour="black",linetype="dotted") +
	theme_bw() +
	coord_flip() + 
	theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black")) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=15)) + 
	theme(axis.title.x = element_text(size=20)) + 
	theme(legend.position = "none")

ggsave("Figures/myopia_coefplot_state.pdf",coef_plot_myopia_state,width=11,height=6)

#---------------------------------#
#### Appendix H: Media Results ####
#---------------------------------#

data_analysis$state_year_newspaper <- paste(data_analysis$state_year, data_analysis$county_newspaper, sep="-")
data_analysis$state_year_newspaper2 <- paste(data_analysis$state_year, data_analysis$dailypaper, sep="-")
data_analysis$county_newspaper_flipped <- 1-data_analysis$county_newspaper

federal_media <- felm(partisanship_federal_delta ~ wages_perworker_real_delta*pres_dem_control*county_newspaper | fips + state_year_newspaper | 0 | fips, data=data_analysis[data_analysis$population_2010 > 20000,])
state_media <- felm(partisanship_state_delta2 ~ wages_perworker_real_delta*pres_dem_control*county_newspaper | fips + state_year_newspaper | 0 | fips, data=data_analysis[data_analysis$population_2010 > 20000,])
local_media <- felm(mayor_demshare_delta  ~ wages_perworker_real_delta*pres_dem_control*county_newspaper | fips + state_year_newspaper | 0 | fips, data=data_analysis[data_analysis$population_2010 > 20000,])
local_media_flipped <- felm(mayor_demshare_delta  ~ wages_perworker_real_delta*pres_dem_control*county_newspaper_flipped | fips + state_year_newspaper | 0 | fips, data=data_analysis[data_analysis$population_2010 > 20000,])

#---------------------------------------------------------------#
#### Figure 3: Media and Accountability in Federal Elections ####
#---------------------------------------------------------------#

coefs_for_plot <- data.frame(
	group = c("Republican president","Democratic president","Difference", # no paper
						"Republican president","Democratic president","Difference"), # with paper
	estimate = c(summary(federal_media)$coefficients[1,1],
							 summary(federal_media)$coefficients[1,1]+summary(federal_media)$coefficients[4,1],
							 summary(federal_media)$coefficients[4,1],
							 summary(federal_media)$coefficients[1,1]+summary(federal_media)$coefficients[5,1],
							 summary(federal_media)$coefficients[1,1]+summary(federal_media)$coefficients[4,1]+summary(federal_media)$coefficients[5,1]+summary(federal_media)$coefficients[7,1],
							 summary(federal_media)$coefficients[4,1] + summary(federal_media)$coefficients[7,1]
	),
	se = c(summary(federal_media)$coefficients[1,2],
				 sqrt(summary(federal_media)$coefficients[1,2]^2+summary(federal_media)$coefficients[4,2]^2 + 2*federal_media$vcv[1,4]),
				 summary(federal_media)$coefficients[4,2],
				 sqrt(summary(federal_media)$coefficients[1,2]^2+summary(federal_media)$coefficients[5,2]^2 + 2*federal_media$vcv[1,5]),
				 sqrt(summary(federal_media)$coefficients[1,2]^2+summary(federal_media)$coefficients[4,2]^2+summary(federal_media)$coefficients[5,2]^2+summary(federal_media)$coefficients[7,2]^2 + 2*federal_media$vcv[1,5]+ 2*federal_media$vcv[1,4]+ 2*federal_media$vcv[4,5]+ 2*federal_media$vcv[1,7]+ 2*federal_media$vcv[4,7] + 2*federal_media$vcv[5,7]),
				 sqrt(summary(federal_media)$coefficients[4,2]^2+summary(federal_media)$coefficients[7,2]^2 + 2*federal_media$vcv[4,7]))
	
)


coefs_for_plot$party <- c("Republican","Democrat","Difference","Republican","Democrat","Difference")
coefs_for_plot$paper <- c("Without paper","Without paper","Without paper","With paper","With paper","With paper")
coefs_for_plot$order <- c(2.15,2,1.85,1.15,1,0.85)

coef_plot_media <- ggplot(data = coefs_for_plot, aes(x = estimate, y = order,shape=party)) +
	geom_errorbarh(data = coefs_for_plot, lwd=1, height=0, aes(y = order, 
																														 xmin = estimate + qnorm(0.025)*se, 
																														 xmax = estimate + qnorm(0.975)*se,
																														 col = party)
	) +
	geom_point(size = 4.75,aes(col=party,shape=party)) + 
	geom_text(data = filter(coefs_for_plot,paper=="Without paper"),
						aes(x = estimate + qnorm(0.975)*se, y=order,label=party,col=party),hjust=-0.15) + 
	scale_x_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare", limits = c(-0.24,0.48),breaks = seq(-0.2,0.5,.1)) +
	scale_y_continuous("",breaks=c(1,2),labels=c("With\npaper","Without\npaper"),limits=c(0.85,2.15)) +
	scale_color_manual(values=c("Democrat"="blue","Republican"="red","Difference" = "black")) + 
  scale_shape_manual(values = c("Republican" = 19,"Democrat" = 17,"Difference" = 15)) + 
  geom_vline(xintercept = 0,size=.5,colour="black",linetype="dotted") +
	theme_bw() +
	theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black")) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=15)) + 
	theme(axis.title.x = element_text(size=20)) +
	theme(legend.position = "none")

ggsave("Figures/media_coefplot_v2.pdf",coef_plot_media,width=9,height=4)


#---------------------------------------------------------------#
#### Appendix H: Media and Accountability in State Elections ####
#---------------------------------------------------------------#

summary(state_media)
coefs_for_plot <- data.frame(
	group = c("Republican president","Democratic president","Difference", # no paper
						"Republican president","Democratic president","Difference"), # with paper
	estimate = c(summary(state_media)$coefficients[1,1],
							 summary(state_media)$coefficients[1,1]+summary(state_media)$coefficients[4,1],
							 summary(state_media)$coefficients[4,1],
							 summary(state_media)$coefficients[1,1]+summary(state_media)$coefficients[5,1],
							 summary(state_media)$coefficients[1,1]+summary(state_media)$coefficients[4,1]+summary(state_media)$coefficients[5,1]+summary(state_media)$coefficients[7,1],
							 summary(state_media)$coefficients[4,1] + summary(state_media)$coefficients[7,1]
	),
	se = c(summary(state_media)$coefficients[1,2],
				 sqrt(summary(state_media)$coefficients[1,2]^2+summary(state_media)$coefficients[4,2]^2 + 2*state_media$vcv[1,4]),
				 summary(state_media)$coefficients[4,2],
				 sqrt(summary(state_media)$coefficients[1,2]^2+summary(state_media)$coefficients[5,2]^2 + 2*state_media$vcv[1,5]),
				 sqrt(summary(state_media)$coefficients[1,2]^2+summary(state_media)$coefficients[4,2]^2+summary(state_media)$coefficients[5,2]^2+summary(state_media)$coefficients[7,2]^2 + 2*state_media$vcv[1,5]+ 2*state_media$vcv[1,4]+ 2*state_media$vcv[4,5]+ 2*state_media$vcv[1,7]+ 2*state_media$vcv[4,7] + 2*state_media$vcv[5,7]),
				 sqrt(summary(state_media)$coefficients[4,2]^2+summary(state_media)$coefficients[7,2]^2 + 2*state_media$vcv[4,7]))
	
)


coefs_for_plot$party <- c("Republican","Democrat","Difference","Republican","Democrat","Difference")
coefs_for_plot$paper <- c("Without paper","Without paper","Without paper","With paper","With paper","With paper")
coefs_for_plot$order <- c(2.15,2,1.85,1.15,1,0.85)

coef_plot_media_state <- ggplot(data = coefs_for_plot, aes(x = estimate, y = order)) +
	geom_errorbarh(data = coefs_for_plot, lwd=1, height=0, aes(y = order, 
																														 xmin = estimate + qnorm(0.025)*se, 
																														 xmax = estimate + qnorm(0.975)*se,
																														 col = party)
	) +
	geom_point(size = 4.75,aes(col=party,shape=party)) + 
	geom_text(data = filter(coefs_for_plot,paper=="Without paper"),
						aes(x = estimate + qnorm(0.975)*se, y=order,label=party,col=party),hjust=-0.15) + 
	scale_x_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare", limits = c(-0.38,0.45),breaks = seq(-0.4,0.5,.1)) +
	scale_y_continuous("",breaks=c(1,2),labels=c("With\npaper","Without\npaper"),limits=c(0.85,2.15)) +
	scale_color_manual(values=c("Democrat"="blue","Republican"="red","Difference" = "black")) + 
	scale_shape_manual(values = c("Republican" = 19,"Democrat" = 17,"Difference" = 15)) + 
	geom_vline(xintercept = 0,size=.5,colour="black",linetype="dotted") +
	theme_bw() +
	theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black")) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=15)) + 
	theme(axis.title.x = element_text(size=20)) +
	theme(legend.position = "none")

ggsave("Figures/media_coefplot_v2_state.pdf",coef_plot_media_state,width=9,height=5)


#---------------------------------------------------------------#
#### Appendix H: Media and Accountability in Local Elections ####
#---------------------------------------------------------------#

coefs_for_plot <- data.frame(
	group = c("Republican president","Democratic president","Difference", # no paper
						"Republican president","Democratic president","Difference"), # with paper
	estimate = c(summary(local_media)$coefficients[1,1],
							 summary(local_media)$coefficients[1,1]+summary(local_media)$coefficients[4,1],
							 summary(local_media)$coefficients[4,1],
							 
							 summary(local_media_flipped)$coefficients[1,1],
							 summary(local_media_flipped)$coefficients[1,1]+summary(local_media_flipped)$coefficients[4,1],
							 summary(local_media_flipped)$coefficients[4,1]
	),
	se = c(summary(local_media)$coefficients[1,2],
				 sqrt(summary(local_media)$coefficients[1,2]^2+summary(local_media)$coefficients[4,2]^2 + 2*local_media$vcv[1,4]),
				 summary(local_media)$coefficients[4,2],
				 summary(local_media_flipped)$coefficients[1,2],
				 sqrt(summary(local_media_flipped)$coefficients[1,2]^2+summary(local_media_flipped)$coefficients[4,2]^2 + 2*local_media_flipped$vcv[1,4]),
				 summary(local_media_flipped)$coefficients[4,2])
)


coefs_for_plot$party <- c("Republican","Democrat","Difference","Republican","Democrat","Difference")
coefs_for_plot$paper <- c("Without paper","Without paper","Without paper","With paper","With paper","With paper")
coefs_for_plot$order <- c(2.15,2,1.85,1.15,1,0.85)

coef_plot_media_local <- ggplot(data = coefs_for_plot, aes(x = estimate, y = order)) +
	geom_errorbarh(data = coefs_for_plot, lwd=1, height=0, aes(y = order, 
																														 xmin = estimate + qnorm(0.025)*se, 
																														 xmax = estimate + qnorm(0.975)*se,
																														 col = party)
	) +
	geom_point(size = 4.75,aes(col=party,shape=party)) + 
	geom_text(data = filter(coefs_for_plot,paper=="Without paper"),
						aes(x = estimate + qnorm(0.975)*se, y=order,label=party,col=party),hjust=-0.15) + 
	scale_x_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare", limits = c(-5,14),breaks = seq(-6,14,4)) +
	scale_y_continuous("",breaks=c(1,2),labels=c("With\npaper","Without\npaper"),limits=c(0.85,2.15)) +
	scale_color_manual(values=c("Democrat"="blue","Republican"="red","Difference" = "black")) + 
	scale_shape_manual(values = c("Republican" = 19,"Democrat" = 17,"Difference" = 15)) + 
	geom_vline(xintercept = 0,size=.5,colour="black",linetype="dotted") +
	theme_bw() +
	theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black")) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=15)) + 
	theme(axis.title.x = element_text(size=20)) +
	theme(legend.position = "none")

ggsave("Figures/media_coefplot_v2_local.pdf",coef_plot_media_local,width=9,height=5)



#### On vs Off-cycle ####
data_analysis$offcycle <- as.numeric(data_analysis$election_type=="offyear")

federal_mid <- felm(partisanship_federal_delta ~ wages_perworker_real_delta*pres_dem_control*midterm | fips + state_year | 0 | fips, data=data_analysis[data_analysis$population_2010 > 20000,])
state_mid <- felm(partisanship_state_delta2 ~ wages_perworker_real_delta*pres_dem_control*midterm | fips + state_year | 0 | fips, data=data_analysis[data_analysis$population_2010 > 20000,])
mayor_offcycle <- felm(mayor_demshare_delta ~ wages_perworker_real_delta*mayor_dem_control*offcycle | fips + state_year | 0 | fips, data=data_analysis[data_analysis$population_2010 > 20000,])
mayor_mid <- felm(mayor_demshare_delta ~ wages_perworker_real_delta*mayor_dem_control*midterm | fips + state_year | 0 | fips, data=data_analysis[data_analysis$population_2010 > 20000,])

## Federal:
summary(federal_mid)
summary(state_mid)
summary(mayor_mid)
summary(mayor_offcycle)


#----------------------------------#
#### Appendix B: Placebo checks ####
#----------------------------------#

lag.new <- function(x, n = 1L, along_with){
  index <- match(along_with - n, along_with, incomparable = NA)
  out <- x[index]
  attributes(out) <- attributes(x)
  out
}

lead.new <- function(x, n = 1L, along_with){
  index <- match(along_with + n, along_with, incomparable = NA)
  out <- x[index]
  attributes(out) <- attributes(x)
  out
}

data_analysis <- group_by(data_analysis, fips) %>%
  mutate( 
    wages_perworker_real_log=log(wages_perworker_real+1)*100,
    wages_perworker_real_delta_lag3 =lag.new(wages_perworker_real_delta,along_with=year,n=3),
    wages_perworker_real_delta_lag2 =lag.new(wages_perworker_real_delta,along_with=year,n=2),
    wages_perworker_real_delta_lag1 =lag.new(wages_perworker_real_delta,along_with=year,n=1),
    wages_perworker_real_lag4 =lag.new(wages_perworker_real_log,along_with=year,n=4),
    wages_perworker_real_lag3 =lag.new(wages_perworker_real_log,along_with=year,n=3),
    wages_perworker_real_lag2 =lag.new(wages_perworker_real_log,along_with=year,n=2),
    wages_perworker_real_lag1 =lag.new(wages_perworker_real_log,along_with=year,n=1),
    wages_perworker_real_delta_fullterm = wages_perworker_real_log - wages_perworker_real_lag4,
    wages_perworker_real_delta_lead1 =lead.new(wages_perworker_real_delta,along_with=year,n=1),
    wages_perworker_real_delta_lead2 =lead.new(wages_perworker_real_delta,along_with=year,n=2),
    wages_perworker_real_delta_lead3 =lead.new(wages_perworker_real_delta,along_with=year,n=3),
    wages_perworker_real_delta_lead4 =lead.new(wages_perworker_real_delta,along_with=year,n=4),
    wages_perworker_real_delta_lead5 =lead.new(wages_perworker_real_delta,along_with=year,n=5),
    wages_perworker_real_lead1 =lead.new(wages_perworker_real_log,along_with=year,n=1),
    wages_perworker_real_lead2 =lead.new(wages_perworker_real_log,along_with=year,n=2),
    wages_perworker_real_lead3 =lead.new(wages_perworker_real_log,along_with=year,n=3),
    wages_perworker_real_lead4 =lead.new(wages_perworker_real_log,along_with=year,n=4),
    wages_perworker_real_lead5 =lead.new(wages_perworker_real_log,along_with=year,n=5),
    partisanship_federal_delta_lagged =lag.new(partisanship_federal_delta,along_with=year,n=2),
    partisanship_federal_lagged =lag.new(partisanship_federal,along_with=year,n=2)
    
  )
federal_check1 <- felm(partisanship_federal_delta ~ wages_perworker_real_delta*pres_dem_control 
											 | fips + state_year | 0 | fips,
											 data=data_analysis[data_analysis$population_2010 > 20000,])

federal_placebo1 <- felm(partisanship_federal_delta ~ wages_perworker_real_delta_lead1*pres_dem_control 
												 | fips + state_year | 0 | fips,
												 data=data_analysis[data_analysis$population_2010 > 20000,])

### expansion of placebo checks to evaluate validity of parallel trends
federal_trends1 <- felm(partisanship_federal_delta~wages_perworker_real_delta_lag3* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends2 <- felm(partisanship_federal_delta~wages_perworker_real_delta_lag2* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends3 <- felm(partisanship_federal_delta~wages_perworker_real_delta_lag1* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends4 <- felm(partisanship_federal_delta~wages_perworker_real_delta*pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends5 <- felm(partisanship_federal_delta~wages_perworker_real_delta_lead1* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends6 <- felm(partisanship_federal_delta~wages_perworker_real_delta_lead2* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends7 <- felm(partisanship_federal_delta~wages_perworker_real_delta_lead3* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends8 <- felm(partisanship_federal_delta~wages_perworker_real_delta_lead4* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends9 <- felm(partisanship_federal_delta~wages_perworker_real_delta_lead5* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])



#-------------------------------------------------------------#
#### Figure B-2(a): Parallel trends for main specification ####
#-------------------------------------------------------------#
library(broom)
parallel_trends <- rbind(tidy(federal_trends9)[3,],
												tidy(federal_trends8)[3,],
												tidy(federal_trends7)[3,],
												tidy(federal_trends6)[3,],
												tidy(federal_trends5)[3,],
												tidy(federal_trends4)[3,],
												tidy(federal_trends3)[3,],
												tidy(federal_trends2)[3,],
												tidy(federal_trends1)[3,])
parallel_trends$term <- rev(seq(-3,5,1))
parallel_trends$term[parallel_trends$term==0] <- "Wage Growth in\nElection Year"
parallel_trends$term[parallel_trends$term==1]<-"+1"
parallel_trends$term[parallel_trends$term==2]<-"+2"
parallel_trends$term[parallel_trends$term==3]<-"+3"
parallel_trends$term[parallel_trends$term==4]<-"+4"
parallel_trends$term[parallel_trends$term==5]<-"+5"
parallel_trends$term <- factor(parallel_trends$term,levels = c("-3","-2","-1","Wage Growth in\nElection Year","+1","+2","+3","+4","+5"),ordered=T)

parallel_trends$plotorder <- c(9:1)

parallel_deltas <- ggplot(data = parallel_trends, aes(x = estimate, y = plotorder)) +
	geom_errorbarh(data = parallel_trends, lwd=1, height=0.0,col="black", 
	               aes(y = plotorder, 
	                   xmin = estimate + qnorm(0.025)*std.error, 
	                   xmax = estimate + qnorm(0.975)*std.error)
	) +
	geom_point(size = 3.75,col="black",shape=15) + 
	scale_x_continuous("Effect of 1% Wage Increase on\nDemocratic Voteshare under\nDemocratic Pres. - Republican Pres.") +
	scale_y_continuous("",breaks=c(1:9),labels=arrange(parallel_trends,plotorder)$term,limits=c(0.9,9.1)) +
  geom_vline(xintercept = 0,size=.5,colour="black",linetype="dotted") +
	geom_hline(yintercept = 4.5, linetype="dashed") + 
	theme_bw() +
	coord_flip() + 
	theme(axis.text.y = element_text(size=10, angle = 0, hjust = 1, color="black")) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=10)) + 
	theme(axis.title.x = element_text(size=15)) +
	theme(legend.position = "none")

ggsave("Figures/parallel_trends_deltas_v2.pdf",parallel_deltas,height=3,width=7)


## Versions with no past wage effects:
# parallel_trends <- filter(parallel_trends,plotorder>3)
# parallel_deltas_nopast <- ggplot(data = parallel_trends, aes(x = estimate, y = plotorder)) +
#   geom_errorbarh(data = parallel_trends, lwd=1, height=0.0,col="black", 
#                  aes(y = plotorder, 
#                      xmin = estimate + qnorm(0.025)*std.error, 
#                      xmax = estimate + qnorm(0.975)*std.error)
#   ) +
#   geom_point(size = 3.75,col="black",shape=15) + 
#   scale_x_continuous("Effect of 1% Wage Increase on\nDemocratic Voteshare under\nDemocratic Pres. - Republican Pres.") +
#   scale_y_continuous("",breaks=c(4:9),labels=arrange(parallel_trends,plotorder)$term,limits=c(3.9,9.1)) +
#   geom_vline(xintercept = 0,size=.5,colour="black",linetype="dotted") +
#   geom_hline(yintercept = 4.5, linetype="dashed") + 
#   theme_bw() +
#   coord_flip() + 
#   theme(axis.text.y = element_text(size=10, angle = 0, hjust = 1, color="black")) +  
#   # theme(axis.title.y = element_blank()) +
#   theme(axis.text.x = element_text(size=10)) + 
#   theme(axis.title.x = element_text(size=15)) +
#   theme(legend.position = "none")
# 
# ggsave("Figures/parallel_trends_deltas_nopast.pdf",parallel_deltas_nopast,height=3,width=7)

#---------------------------------------------------------------------------#
#### Figure B-2(b): Parallel trends for level VS and wages specification ####
#---------------------------------------------------------------------------#

federal_trends1_levels <- felm(partisanship_federal~wages_perworker_real_lag3* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends2_levels <- felm(partisanship_federal~wages_perworker_real_lag2* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends3_levels <- felm(partisanship_federal~wages_perworker_real_lag1* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends4_levels <- felm(partisanship_federal~wages_perworker_real_log*pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends5_levels <- felm(partisanship_federal~wages_perworker_real_lead1* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends6_levels <- felm(partisanship_federal~wages_perworker_real_lead2* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends7_levels <- felm(partisanship_federal~wages_perworker_real_lead3* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends8_levels <- felm(partisanship_federal~wages_perworker_real_lead4* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends9_levels <- felm(partisanship_federal~wages_perworker_real_lead5* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])


parallel_trends <- rbind(tidy(federal_trends9_levels)[3,],
												 tidy(federal_trends8_levels)[3,],
												 tidy(federal_trends7_levels)[3,],
												 tidy(federal_trends6_levels)[3,],
												 tidy(federal_trends5_levels)[3,],
												 tidy(federal_trends4_levels)[3,],
												 tidy(federal_trends3_levels)[3,],
												 tidy(federal_trends2_levels)[3,],
												 tidy(federal_trends1_levels)[3,])
parallel_trends$term <- rev(seq(-3,5,1))
parallel_trends$term[parallel_trends$term==0] <- "Wage Growth in\nElection Year"
parallel_trends$term[parallel_trends$term==1]<-"+1"
parallel_trends$term[parallel_trends$term==2]<-"+2"
parallel_trends$term[parallel_trends$term==3]<-"+3"
parallel_trends$term[parallel_trends$term==4]<-"+4"
parallel_trends$term[parallel_trends$term==5]<-"+5"
parallel_trends$term <- factor(parallel_trends$term,levels = c("-3","-2","-1","Wage Growth in\nElection Year","+1","+2","+3","+4","+5"),ordered=T)

parallel_trends$plotorder <- c(9:1)

parallel_levels <- ggplot(data = parallel_trends, aes(x = estimate, y = plotorder)) +
	geom_errorbarh(data = parallel_trends, lwd=1, height=0.0,col="black", 
								 aes(y = plotorder, 
								 		xmin = estimate + qnorm(0.025)*std.error, 
								 		xmax = estimate + qnorm(0.975)*std.error)
	) +
	geom_point(size = 3.75,col="black",shape=15) + 
	scale_x_continuous("Effect of 1% Wage Increase on\nDemocratic Voteshare under\nDemocratic Pres. - Republican Pres.") +
	scale_y_continuous("",breaks=c(1:9),labels=arrange(parallel_trends,plotorder)$term,limits=c(0.9,9.1)) +
	geom_vline(xintercept = 0,size=.5,colour="black",linetype="dotted") +
	geom_hline(yintercept = 4.5, linetype="dashed") + 
	theme_bw() +
	coord_flip() + 
	theme(axis.text.y = element_text(size=10, angle = 0, hjust = 1, color="black")) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=10)) + 
	theme(axis.title.x = element_text(size=15)) +
	theme(legend.position = "none")

ggsave("Figures/parallel_trends_levels_v2.pdf",parallel_levels,height=3,width=7)



#------------------------------------------------------------------------------#
#### Figure B-2(c): Parallel trends for level VS, delta wages specification ####
#------------------------------------------------------------------------------#
federal_trends1_levelVS <- felm(partisanship_federal~wages_perworker_real_delta_lag3* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends2_levelVS <- felm(partisanship_federal~wages_perworker_real_delta_lag2* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends3_levelVS <- felm(partisanship_federal~wages_perworker_real_delta_lag1* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends4_levelVS <- felm(partisanship_federal~wages_perworker_real_delta*pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends5_levelVS <- felm(partisanship_federal~wages_perworker_real_delta_lead1* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends6_levelVS <- felm(partisanship_federal~wages_perworker_real_delta_lead2* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends7_levelVS <- felm(partisanship_federal~wages_perworker_real_delta_lead3* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends8_levelVS <- felm(partisanship_federal~wages_perworker_real_delta_lead4* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])
federal_trends9_levelVS <- felm(partisanship_federal~wages_perworker_real_delta_lead5* pres_dem_control |fips+state_year|0|fips, data=data_analysis[data_analysis$population_2010 > 20000,])


parallel_trends <- rbind(tidy(federal_trends9_levelVS)[3,],
												 tidy(federal_trends8_levelVS)[3,],
												 tidy(federal_trends7_levelVS)[3,],
												 tidy(federal_trends6_levelVS)[3,],
												 tidy(federal_trends5_levelVS)[3,],
												 tidy(federal_trends4_levelVS)[3,],
												 tidy(federal_trends3_levelVS)[3,],
												 tidy(federal_trends2_levelVS)[3,],
												 tidy(federal_trends1_levelVS)[3,])
parallel_trends$term <- rev(seq(-3,5,1))
parallel_trends$term[parallel_trends$term==0] <- "Wage Growth in\nElection Year"
parallel_trends$term[parallel_trends$term==1]<-"+1"
parallel_trends$term[parallel_trends$term==2]<-"+2"
parallel_trends$term[parallel_trends$term==3]<-"+3"
parallel_trends$term[parallel_trends$term==4]<-"+4"
parallel_trends$term[parallel_trends$term==5]<-"+5"
parallel_trends$term <- factor(parallel_trends$term,levels = c("-3","-2","-1","Wage Growth in\nElection Year","+1","+2","+3","+4","+5"),ordered=T)

parallel_trends$plotorder <- c(9:1)

parallel_levelVS <- ggplot(data = parallel_trends, aes(x = estimate, y = plotorder)) +
	geom_errorbarh(data = parallel_trends, lwd=1, height=0.0,col="black", 
								 aes(y = plotorder, 
								 		xmin = estimate + qnorm(0.025)*std.error, 
								 		xmax = estimate + qnorm(0.975)*std.error)
	) +
	geom_point(size = 3.75,col="black",shape=15) + 
	scale_x_continuous("Effect of 1% Wage Increase on\nDemocratic Voteshare under\nDemocratic Pres. - Republican Pres.") +
	scale_y_continuous("",breaks=c(1:9),labels=arrange(parallel_trends,plotorder)$term,limits=c(0.9,9.1)) +
	geom_vline(xintercept = 0,size=.5,colour="black",linetype="dotted") +
	geom_hline(yintercept = 4.5, linetype="dashed") + 
	theme_bw() +
	coord_flip() + 
	theme(axis.text.y = element_text(size=10, angle = 0, hjust = 1, color="black")) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=10)) + 
	theme(axis.title.x = element_text(size=15)) +
	theme(legend.position = "none")

ggsave("Figures/parallel_trends_levelVS.pdf",parallel_levelVS,height=3,width=7)



#--------------------------------#
#### Figure 2: Main coefplots ####
#--------------------------------#
pres_main <- felm(pres_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
									| fips + state_year |0| fips, 
									data=data_analysis[data_analysis$population_2010 > 20000,])
sen_main <- felm(sen_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
								 | fips + state_year |0| fips, 
								 data=data_analysis[data_analysis$population_2010 > 20000,])
house_main <- felm(house_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
									 | fips + state_year |0| fips, 
									 data=data_analysis[data_analysis$population_2010 > 20000,])
federal_main <- felm(partisanship_federal_delta ~ wages_perworker_real_delta*pres_dem_control
										 | fips + state_year |0| fips, 
										 data=data_analysis[data_analysis$population_2010 > 20000,])
gov_main <- felm(gov_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
								 | fips + state_year |0| fips, 
								 data=data_analysis[data_analysis$population_2010 > 20000,])
stateexec_main <- felm(stateoffice_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
											 | fips + state_year |0| fips, 
											 data=data_analysis[data_analysis$population_2010 > 20000,])
sldl_main <- felm(sldl_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
									| fips + state_year |0| fips, 
									data=data_analysis[data_analysis$population_2010 > 20000,])
sldu_main <- felm(sldu_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
									| fips + state_year |0| fips, 
									data=data_analysis[data_analysis$population_2010 > 20000,])
state_main <- felm(partisanship_state_delta ~ wages_perworker_real_delta*pres_dem_control
									 | fips + state_year |0| fips, 
									 data=data_analysis[data_analysis$population_2010 > 20000,])
county_main <- felm(countyleg_avg_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
										| fips + state_year |0| fips, 
										data=data_analysis[data_analysis$population_2010 > 20000,])
mayor_main <- felm(mayor_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
									 | fips + state_year |0| fips, 
									 data=data_analysis[data_analysis$population_2010 > 20000,])

coefs_for_plot <- data.frame(
	group = c(rep(c("President","Senate","House","Federal Avg","Governor","State Execs","State House","State Avg","County","Mayor"),each=3)),
	estimate = c(summary(pres_main)$coefficients[1,1],
							 summary(pres_main)$coefficients[1,1]+summary(pres_main)$coefficients[3,1],
							 summary(pres_main)$coefficients[3,1],
							 summary(sen_main)$coefficients[1,1],
							 summary(sen_main)$coefficients[1,1]+summary(sen_main)$coefficients[3,1],
							 summary(sen_main)$coefficients[3,1],
							 summary(house_main)$coefficients[1,1],
							 summary(house_main)$coefficients[1,1]+summary(house_main)$coefficients[3,1],
							 summary(house_main)$coefficients[3,1],
							 summary(federal_main)$coefficients[1,1],
							 summary(federal_main)$coefficients[1,1]+summary(federal_main)$coefficients[3,1],
							 summary(federal_main)$coefficients[3,1],
							 
							 summary(gov_main)$coefficients[1,1],
							 summary(gov_main)$coefficients[1,1]+summary(gov_main)$coefficients[3,1],
							 summary(gov_main)$coefficients[3,1],
							 summary(stateexec_main)$coefficients[1,1],
							 summary(stateexec_main)$coefficients[1,1]+summary(stateexec_main)$coefficients[3,1],
							 summary(stateexec_main)$coefficients[3,1],
							 summary(sldl_main)$coefficients[1,1],
							 summary(sldl_main)$coefficients[1,1]+summary(sldl_main)$coefficients[3,1],
							 summary(sldl_main)$coefficients[3,1],
							 summary(state_main)$coefficients[1,1],
							 summary(state_main)$coefficients[1,1]+summary(state_main)$coefficients[3,1],
							 summary(state_main)$coefficients[3,1],
							 
							 summary(county_main)$coefficients[1,1],
							 summary(county_main)$coefficients[1,1]+summary(county_main)$coefficients[3,1],
							 summary(county_main)$coefficients[3,1],
							 
							 summary(mayor_main)$coefficients[1,1],
							 summary(mayor_main)$coefficients[1,1]+summary(mayor_main)$coefficients[3,1],
							 summary(mayor_main)$coefficients[3,1]
	),
	se = c(summary(pres_main)$coefficients[1,2],
				 sqrt(summary(pres_main)$coefficients[1,2]^2+summary(pres_main)$coefficients[3,2]^2 + 2*pres_main$vcv[1,3]),
				 summary(pres_main)$coefficients[3,2],
				 summary(sen_main)$coefficients[1,2],
				 sqrt(summary(sen_main)$coefficients[1,2]^2+summary(sen_main)$coefficients[3,2]^2 + 2*sen_main$vcv[1,3]),
				 summary(sen_main)$coefficients[3,2],
				 summary(house_main)$coefficients[1,2],
				 sqrt(summary(house_main)$coefficients[1,2]^2+summary(house_main)$coefficients[3,2]^2 + 2*house_main$vcv[1,3]),
				 summary(house_main)$coefficients[3,2],
				 summary(federal_main)$coefficients[1,2],
				 sqrt(summary(federal_main)$coefficients[1,2]^2+summary(federal_main)$coefficients[3,2]^2 + 2*federal_main$vcv[1,3]),
				 summary(federal_main)$coefficients[3,2],
				 
				 summary(gov_main)$coefficients[1,2],
				 sqrt(summary(gov_main)$coefficients[1,2]^2+summary(gov_main)$coefficients[3,2]^2 + 2*gov_main$vcv[1,3]),
				 summary(gov_main)$coefficients[3,2],
				 summary(stateexec_main)$coefficients[1,2],
				 sqrt(summary(stateexec_main)$coefficients[1,2]^2+summary(stateexec_main)$coefficients[3,2]^2 + 2*stateexec_main$vcv[1,3]),
				 summary(stateexec_main)$coefficients[3,2],
				 summary(sldl_main)$coefficients[1,2],
				 sqrt(summary(sldl_main)$coefficients[1,2]^2+summary(sldl_main)$coefficients[3,2]^2 + 2*sldl_main$vcv[1,3]),
				 summary(sldl_main)$coefficients[3,2],
				 summary(state_main)$coefficients[1,2],
				 sqrt(summary(state_main)$coefficients[1,2]^2+summary(state_main)$coefficients[3,2]^2 + 2*state_main$vcv[1,3]),
				 summary(state_main)$coefficients[3,2],
				 
				 summary(county_main)$coefficients[1,2],
				 sqrt(summary(county_main)$coefficients[1,2]^2+summary(county_main)$coefficients[3,2]^2 + 2*county_main$vcv[1,3]),
				 summary(county_main)$coefficients[3,2],
				 summary(mayor_main)$coefficients[1,2],
				 sqrt(summary(mayor_main)$coefficients[1,2]^2+summary(mayor_main)$coefficients[3,2]^2 + 2*mayor_main$vcv[1,3]),
				 summary(mayor_main)$coefficients[3,2]
	)
)

coefs_for_plot$party <- factor(rep(c("Republican","Democrat","Difference"),10),levels = c("Democrat","Republican","Difference"),ordered=T)
coefs_for_plot$order <- c(10.15,10,9.85,9.15,9,8.85,8.15,8,7.85,7.15,7,6.85,6.15,6,5.85,5.15,5,4.85,4.15,4,3.85,3.15,3,2.85,2.15,2,1.85,1.15,1,0.85)
coefs_for_plot$fontface <- rep(c("plain","plain","plain","bold.italic","plain","plain","plain","bold.italic","plain","plain"),each=3)

coef_plot_all <- ggplot(data = filter(coefs_for_plot,order>2.5), aes(y = estimate, x = order,color=party)) +
	geom_errorbar(data = filter(coefs_for_plot,order>2.5), lwd=1, width=0.0, aes(x = order, 
																														 ymin = estimate + qnorm(0.025)*se, 
																														 ymax = estimate + qnorm(0.975)*se,
																														 col=party)
	) +
	geom_point(size = 3.75,aes(shape=party)) + 
	geom_text(data = filter(coefs_for_plot,group=="President"),
						aes(y = estimate + qnorm(0.975)*se, x=order,label=party),hjust=-0.15) + 
	scale_y_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare", limits = c(-0.3,0.42),breaks = seq(-0.4,0.4,.1)) +
	scale_x_continuous("",breaks=c(10:1),limits=c(2.5,10.15),labels=c("President","Senate","House","Federal Average","Governor","Downballot\nState Offices","State House","State Average","County","Local")) +
	annotate(x = 2.5,y=-0.27,geom = "text",label="Republican candidate does better",col="red",hjust=0,size=5) +	
	annotate(x = 2.5,y=-0.28,xend=2.5,yend=-.3,geom = "segment",arrow=arrow(type = "closed",angle = 20),col="red") +	
	annotate(x = 2.5,y=0.37,geom = "text",label="Democratic candidate does better",col="blue",hjust=1,size=5) +	
  annotate(x = 2.5,y=0.38,xend=2.5,yend=.4,geom = "segment",arrow=arrow(type = "closed",angle = 20),col="blue") +	
  scale_color_manual(breaks = c("Democrat","Republican","Difference"),values=c("blue","red","black")) + 
	scale_shape_manual(values = c("Republican" = 19,"Democrat" = 17,"Difference" = 15)) + 
	geom_hline(yintercept = 0,size=.5,colour="black",linetype="dotted") +
	theme_bw() +
	coord_flip() + 
	theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black",
																	 face=filter(coefs_for_plot,order>2.5 & party=="Democrat")$fontface)) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=15)) + 
	theme(axis.title.x = element_text(size=20)) + 
	theme(legend.position = "none")

ggsave("Figures/coefplot_all.pdf",coef_plot_all,width=11,height=6)


## Local offices:
coef_plot_local <- ggplot(data = filter(coefs_for_plot,order<2.5), aes(y = estimate, x = order,color=party)) +
	geom_errorbar(data = filter(coefs_for_plot,order<2.5), lwd=1, width=0.0, aes(x = order, 
																																													 ymin = estimate + qnorm(0.025)*se, 
																																													 ymax = estimate + qnorm(0.975)*se,
																																													 col=party)
	) +
	geom_point(size = 3.75,aes(shape=party)) + 
	geom_text(data = filter(coefs_for_plot,group=="County"),
						aes(y = estimate + qnorm(0.975)*se, x=order,label=party),hjust=-0.15) + 
	scale_y_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare",limits=c(-3,3.2),breaks=seq(-3,3,0.5)) +
	scale_x_continuous("",breaks=c(10:1),limits=c(0.4,2.15),labels=c("President","Senate","House","Federal Avg","Governor","Downballot\nState Offices","State House","State Avg","County\nLegislature","Mayor")) +
	scale_color_manual(breaks = c("Democrat","Republican","Difference"),values=c("blue","red","black")) + 
	scale_shape_manual(values = c("Republican" = 19,"Democrat" = 17,"Difference" = 15)) + 
	geom_hline(yintercept = 0,size=.5,colour="black",linetype="dotted") +
	annotate(x = 0.5,y=-2.7,geom = "text",label="Republican candidate does better",col="red",hjust=0,size=5) +	
	annotate(x = 0.5,y=-2.9,xend=0.5,yend=-2.93,geom = "segment",arrow=arrow(type = "closed",angle = 20),col="red") +	
	annotate(x = 0.5,y=2.7,geom = "text",label="Democratic candidate does better",col="blue",hjust=1,size=5) +	
	annotate(x = 0.5,y=2.9,xend=0.5,yend=2.93,geom = "segment",arrow=arrow(type = "closed",angle = 20),col="blue") +		theme_bw() +
	coord_flip() + 
	theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black")) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=15)) + 
	theme(axis.title.x = element_text(size=20)) + 
	theme(legend.position = "none")

ggsave("Figures/coefplot_local.pdf",coef_plot_local,width=11,height=3)

#------------------------------------#
#### Figure D-6: Coefplot, no FEs ####
#------------------------------------#

pres_main_nofes <- felm(pres_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
                        | state_year |0| fips, 
                        data=data_analysis[data_analysis$population_2010 > 20000,])
sen_main_nofes <- felm(sen_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
                       | state_year |0| fips, 
                       data=data_analysis[data_analysis$population_2010 > 20000,])
house_main_nofes <- felm(house_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
                         | state_year |0| fips, 
                         data=data_analysis[data_analysis$population_2010 > 20000,])
federal_main_nofes <- felm(partisanship_federal_delta ~ wages_perworker_real_delta*pres_dem_control
                           | state_year |0| fips, 
                           data=data_analysis[data_analysis$population_2010 > 20000,])
gov_main_nofes <- felm(gov_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
                       | state_year |0| fips, 
                       data=data_analysis[data_analysis$population_2010 > 20000,])
stateexec_main_nofes <- felm(stateoffice_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
                             | state_year |0| fips, 
                             data=data_analysis[data_analysis$population_2010 > 20000,])
sldl_main_nofes <- felm(sldl_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
                        | state_year |0| fips, 
                        data=data_analysis[data_analysis$population_2010 > 20000,])
sldu_main_nofes <- felm(sldu_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
                        | state_year |0| fips, 
                        data=data_analysis[data_analysis$population_2010 > 20000,])
state_main_nofes <- felm(partisanship_state_delta ~ wages_perworker_real_delta*pres_dem_control
                         | state_year |0| fips, 
                         data=data_analysis[data_analysis$population_2010 > 20000,])
county_main_nofes <- felm(countyleg_avg_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
                          | state_year |0| fips, 
                          data=data_analysis[data_analysis$population_2010 > 20000,])
mayor_main_nofes <- felm(mayor_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
                         | state_year |0| fips, 
                         data=data_analysis[data_analysis$population_2010 > 20000,])

coefs_for_plot <- data.frame(
  group = c(rep(c("President","Senate","House","Federal Avg","Governor","State Execs","State House","State Avg","County","Mayor"),each=3)),
  estimate = c(summary(pres_main_nofes)$coefficients[1,1],
               summary(pres_main_nofes)$coefficients[1,1]+summary(pres_main_nofes)$coefficients[3,1],
               summary(pres_main_nofes)$coefficients[3,1],
               summary(sen_main_nofes)$coefficients[1,1],
               summary(sen_main_nofes)$coefficients[1,1]+summary(sen_main_nofes)$coefficients[3,1],
               summary(sen_main_nofes)$coefficients[3,1],
               summary(house_main_nofes)$coefficients[1,1],
               summary(house_main_nofes)$coefficients[1,1]+summary(house_main_nofes)$coefficients[3,1],
               summary(house_main_nofes)$coefficients[3,1],
               summary(federal_main_nofes)$coefficients[1,1],
               summary(federal_main_nofes)$coefficients[1,1]+summary(federal_main_nofes)$coefficients[3,1],
               summary(federal_main_nofes)$coefficients[3,1],
               
               summary(gov_main_nofes)$coefficients[1,1],
               summary(gov_main_nofes)$coefficients[1,1]+summary(gov_main_nofes)$coefficients[3,1],
               summary(gov_main_nofes)$coefficients[3,1],
               summary(stateexec_main_nofes)$coefficients[1,1],
               summary(stateexec_main_nofes)$coefficients[1,1]+summary(stateexec_main_nofes)$coefficients[3,1],
               summary(stateexec_main_nofes)$coefficients[3,1],
               summary(sldl_main_nofes)$coefficients[1,1],
               summary(sldl_main_nofes)$coefficients[1,1]+summary(sldl_main_nofes)$coefficients[3,1],
               summary(sldl_main_nofes)$coefficients[3,1],
               summary(state_main_nofes)$coefficients[1,1],
               summary(state_main_nofes)$coefficients[1,1]+summary(state_main_nofes)$coefficients[3,1],
               summary(state_main_nofes)$coefficients[3,1],
               
               summary(county_main_nofes)$coefficients[1,1],
               summary(county_main_nofes)$coefficients[1,1]+summary(county_main_nofes)$coefficients[3,1],
               summary(county_main_nofes)$coefficients[3,1],
               
               summary(mayor_main_nofes)$coefficients[1,1],
               summary(mayor_main_nofes)$coefficients[1,1]+summary(mayor_main_nofes)$coefficients[3,1],
               summary(mayor_main_nofes)$coefficients[3,1]
  ),
  se = c(summary(pres_main_nofes)$coefficients[1,2],
         sqrt(summary(pres_main_nofes)$coefficients[1,2]^2+summary(pres_main_nofes)$coefficients[3,2]^2 + 2*pres_main_nofes$vcv[1,3]),
         summary(pres_main_nofes)$coefficients[3,2],
         summary(sen_main_nofes)$coefficients[1,2],
         sqrt(summary(sen_main_nofes)$coefficients[1,2]^2+summary(sen_main_nofes)$coefficients[3,2]^2 + 2*sen_main_nofes$vcv[1,3]),
         summary(sen_main_nofes)$coefficients[3,2],
         summary(house_main_nofes)$coefficients[1,2],
         sqrt(summary(house_main_nofes)$coefficients[1,2]^2+summary(house_main_nofes)$coefficients[3,2]^2 + 2*house_main_nofes$vcv[1,3]),
         summary(house_main_nofes)$coefficients[3,2],
         summary(federal_main_nofes)$coefficients[1,2],
         sqrt(summary(federal_main_nofes)$coefficients[1,2]^2+summary(federal_main_nofes)$coefficients[3,2]^2 + 2*federal_main_nofes$vcv[1,3]),
         summary(federal_main_nofes)$coefficients[3,2],
         
         summary(gov_main_nofes)$coefficients[1,2],
         sqrt(summary(gov_main_nofes)$coefficients[1,2]^2+summary(gov_main_nofes)$coefficients[3,2]^2 + 2*gov_main_nofes$vcv[1,3]),
         summary(gov_main_nofes)$coefficients[3,2],
         summary(stateexec_main_nofes)$coefficients[1,2],
         sqrt(summary(stateexec_main_nofes)$coefficients[1,2]^2+summary(stateexec_main_nofes)$coefficients[3,2]^2 + 2*stateexec_main_nofes$vcv[1,3]),
         summary(stateexec_main_nofes)$coefficients[3,2],
         summary(sldl_main_nofes)$coefficients[1,2],
         sqrt(summary(sldl_main_nofes)$coefficients[1,2]^2+summary(sldl_main_nofes)$coefficients[3,2]^2 + 2*sldl_main_nofes$vcv[1,3]),
         summary(sldl_main_nofes)$coefficients[3,2],
         summary(state_main_nofes)$coefficients[1,2],
         sqrt(summary(state_main_nofes)$coefficients[1,2]^2+summary(state_main_nofes)$coefficients[3,2]^2 + 2*state_main_nofes$vcv[1,3]),
         summary(state_main_nofes)$coefficients[3,2],
         
         summary(county_main_nofes)$coefficients[1,2],
         sqrt(summary(county_main_nofes)$coefficients[1,2]^2+summary(county_main_nofes)$coefficients[3,2]^2 + 2*county_main_nofes$vcv[1,3]),
         summary(county_main_nofes)$coefficients[3,2],
         summary(mayor_main_nofes)$coefficients[1,2],
         sqrt(summary(mayor_main_nofes)$coefficients[1,2]^2+summary(mayor_main_nofes)$coefficients[3,2]^2 + 2*mayor_main_nofes$vcv[1,3]),
         summary(mayor_main_nofes)$coefficients[3,2]
  )
)

coefs_for_plot$party <- factor(rep(c("Republican","Democrat","Difference"),10),levels = c("Democrat","Republican","Difference"),ordered=T)
coefs_for_plot$order <- c(10.15,10,9.85,9.15,9,8.85,8.15,8,7.85,7.15,7,6.85,6.15,6,5.85,5.15,5,4.85,4.15,4,3.85,3.15,3,2.85,2.15,2,1.85,1.15,1,0.85)
coefs_for_plot$fontface <- rep(c("plain","plain","plain","bold.italic","plain","plain","plain","bold.italic","plain","plain"),each=3)

coef_plot_all <- ggplot(data = filter(coefs_for_plot,order>2.5), aes(y = estimate, x = order,color=party)) +
  geom_errorbar(data = filter(coefs_for_plot,order>2.5), lwd=1, width=0.0, aes(x = order, 
                                                                               ymin = estimate + qnorm(0.025)*se, 
                                                                               ymax = estimate + qnorm(0.975)*se,
                                                                               col=party)
  ) +
  geom_point(size = 3.75,aes(shape=party)) + 
  geom_text(data = filter(coefs_for_plot,group=="President"),
            aes(y = estimate + qnorm(0.975)*se, x=order,label=party),hjust=-0.15) + 
  scale_y_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare,\nNo County-FEs", limits = c(-0.3,0.4),breaks = seq(-0.4,0.4,.1)) +
  scale_x_continuous("",breaks=c(10:1),labels=c("President","Senate","House","Federal Average","Governor","Downballot\nState Offices","State House","State Average","County","Local")) +
  scale_color_manual(breaks = c("Democrat","Republican","Difference"),values=c("blue","red","black")) + 
	scale_shape_manual(values = c("Republican" = 19,"Democrat" = 17,"Difference" = 15)) + 
	geom_hline(yintercept = 0,size=.5,colour="black",linetype="dotted") +
  theme_bw() +
  coord_flip() + 
  theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black",
                                   face=filter(coefs_for_plot,order>2.5 & party=="Democrat")$fontface)) +  
  # theme(axis.title.y = element_blank()) +
  theme(axis.text.x = element_text(size=15)) + 
  theme(axis.title.x = element_text(size=20)) + 
  theme(legend.position = "none")

ggsave("Figures/coefplot_nofes_all.pdf",coef_plot_all,width=11,height=6.5)




#------------------------------------------------------------------#
#### Figure E-7: Coefplot for incumbent accountability w/o pres ####
#------------------------------------------------------------------#

senate_incumbency_nopres <- felm(sen_demshare_delta ~ wages_perworker_real_delta*senate_dem_incumb
													 | fips + state_year |0| fips, data=data_analysis[data_analysis$population_2010 > 20000,])
house_incumbency_nopres <- felm(house_demshare_delta ~ wages_perworker_real_delta*house_dem_incumb 
													| fips + state_year |0| fips, data=data_analysis[data_analysis$population_2010 > 20000,])
gov_incumbency_nopres <- felm(gov_demshare_delta ~ wages_perworker_real_delta*gov_dem_control 
												| fips + state_year |0| fips, data=data_analysis[data_analysis$population_2010 > 20000,])
sldl_incumbency_nopres <- felm(sldl_demshare_delta ~ wages_perworker_real_delta*sldl_dem_incumb 
												 | fips + state_year |0| fips, data=data_analysis[data_analysis$population_2010 > 20000,])
county_incumbency_nopres <- felm(countyleg_avg_demshare_delta ~ wages_perworker_real_delta*county_dem_control 
													 | fips + state_year |0| fips, data=data_analysis[data_analysis$population_2010 > 20000,])



coefs_for_plot <- data.frame(
	group = c(rep(c("Senate","House","Governor","State House","County"),each=3)),
	estimate = c(summary(senate_incumbency_nopres)$coefficients[1,1], # Rep incumb
							 summary(senate_incumbency_nopres)$coefficients[1,1]+summary(senate_incumbency_nopres)$coefficients[3,1], # Dem incumb
							 summary(senate_incumbency_nopres)$coefficients[3,1],
							 
							 summary(house_incumbency_nopres)$coefficients[1,1],
							 summary(house_incumbency_nopres)$coefficients[1,1]+summary(house_incumbency_nopres)$coefficients[3,1],
							 summary(house_incumbency_nopres)$coefficients[3,1],
							 
							 summary(gov_incumbency_nopres)$coefficients[1,1],
							 summary(gov_incumbency_nopres)$coefficients[1,1]+summary(gov_incumbency_nopres)$coefficients[3,1],
							 summary(gov_incumbency_nopres)$coefficients[3,1],
							 
							 summary(sldl_incumbency_nopres)$coefficients[1,1],
							 summary(sldl_incumbency_nopres)$coefficients[1,1]+summary(sldl_incumbency_nopres)$coefficients[3,1],
							 summary(sldl_incumbency_nopres)$coefficients[3,1],
							 
							 summary(county_incumbency_nopres)$coefficients[1,1],
							 summary(county_incumbency_nopres)$coefficients[1,1]+summary(county_incumbency_nopres)$coefficients[3,1],
							 summary(county_incumbency_nopres)$coefficients[3,1]
	),
	se = c(
		summary(senate_incumbency_nopres)$coefficients[1,2],
		sqrt(summary(senate_incumbency_nopres)$coefficients[1,2]^2+summary(senate_incumbency_nopres)$coefficients[3,2]^2 + 2*senate_incumbency_nopres$vcv[1,3]),
		summary(senate_incumbency_nopres)$coefficients[3,2],
		
		summary(house_incumbency_nopres)$coefficients[1,2],
		sqrt(summary(house_incumbency_nopres)$coefficients[1,2]^2+summary(house_incumbency_nopres)$coefficients[3,2]^2 + 2*house_incumbency_nopres$vcv[1,3]),
		summary(house_incumbency_nopres)$coefficients[3,2],
		
		summary(gov_incumbency_nopres)$coefficients[1,2],
		sqrt(summary(gov_incumbency_nopres)$coefficients[1,2]^2+summary(gov_incumbency_nopres)$coefficients[3,2]^2 + 2*gov_incumbency_nopres$vcv[1,3]),
		summary(gov_incumbency_nopres)$coefficients[3,2],
		
		summary(sldl_incumbency_nopres)$coefficients[1,2],
		sqrt(summary(sldl_incumbency_nopres)$coefficients[1,2]^2+summary(sldl_incumbency_nopres)$coefficients[3,2]^2 + 2*sldl_incumbency_nopres$vcv[1,3]),
		summary(sldl_incumbency_nopres)$coefficients[3,2],
		
		summary(county_incumbency_nopres)$coefficients[1,2],
		sqrt(summary(county_incumbency_nopres)$coefficients[1,2]^2+summary(county_incumbency_nopres)$coefficients[3,2]^2 + 2*county_incumbency_nopres$vcv[1,3]),
		summary(county_incumbency_nopres)$coefficients[3,2]
		
	)
)

coefs_for_plot$party <- factor(rep(c("Republican Incumbent","Democratic Incumbent","Difference"),5),levels = c("Republican Incumbent","Democratic Incumbent","Difference"),ordered=T)
coefs_for_plot$order <- c(5.15,5,4.85,4.15,4,3.85,3.15,3,2.85,2.15,2,1.85,1.15,1,0.85)


coef_plot_nopres_all <- ggplot(data = coefs_for_plot, aes(y = estimate, x = order,color=party)) +
	geom_errorbar(lwd=1, width=0.0, aes(x = order, 
																			ymin = estimate + qnorm(0.025)*se, 
																			ymax = estimate + qnorm(0.975)*se,
																			col=party,
																			lty=party)
	) +
	geom_point(size = 3.75,aes(shape=party)) + 
	geom_text(data = filter(coefs_for_plot,group=="Senate"),
						aes(y = estimate + qnorm(0.975)*se, x=order,label=party),hjust=-0.15) + 
	scale_y_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare", limits = c(-1.5,1.08),breaks = round(seq(-1.6,1.2,.4),2)) +
	scale_x_continuous("",breaks=c(5:1),labels=c("Senate","House","Governor","State House","County")) +
	scale_color_manual(values = c("Republican Incumbent" = "red","Democratic Incumbent" = "blue","Difference" = "black")) + 
	scale_shape_manual(values = c("Republican Incumbent" = 19,"Democratic Incumbent" = 17,"Difference" = 15)) + 
	scale_linetype_manual(values = c("Republican Incumbent" = 1,"Democratic Incumbent" = 1,"Difference" = 1)) + 
	annotate(x = 0.5,y=-1.2,geom = "text",label="Republican candidate does better",col="red",hjust=0,size=5) +	
	annotate(x = 0.5,y=-1.24,xend=0.5,yend=-1.27,geom = "segment",arrow=arrow(type = "closed",angle = 20),col="red") +	
	annotate(x = 0.5,y=1.0,geom = "text",label="Democratic candidate does better",col="blue",hjust=1,size=5) +	
	annotate(x = 0.5,y=1.04,xend=0.5,yend=1.07,geom = "segment",arrow=arrow(type = "closed",angle = 20),col="blue") +	
	geom_hline(yintercept = 0,size=.5,colour="black",linetype="dotted") +
	theme_bw() +
	coord_flip() + 
	theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black")) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=15)) + 
	theme(axis.title.x = element_text(size=20)) + 
	theme(legend.position = "none")

ggsave("Figures/coefplot_inc_nopres_all.pdf",coef_plot_nopres_all,width=11,height=6)

coef_plot_nopres_fedstate <- ggplot(data = filter(coefs_for_plot,order>1.5), aes(y = estimate, x = order,color=party)) +
  geom_errorbar(lwd=1, width=0.0, aes(x = order, 
                                      ymin = estimate + qnorm(0.025)*se, 
                                      ymax = estimate + qnorm(0.975)*se,
                                      col=party,
                                      lty=party)
  ) +
  geom_point(size = 3.75,aes(shape=party)) + 
  geom_text(data = filter(coefs_for_plot,group=="Senate"),
            aes(y = estimate + qnorm(0.975)*se, x=order,label=party),hjust=-0.15) + 
  scale_y_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare", limits = c(-0.4,0.4),breaks = round(seq(-1.6,0.6,.2),2)) +
  scale_x_continuous("",breaks=c(5:1),limits=c(1.4,5.15),labels=c("Senate","House","Governor","State House","County")) +
  scale_color_manual(values = c("Republican Incumbent" = "red","Democratic Incumbent" = "blue","Difference" = "black")) + 
  scale_shape_manual(values = c("Republican Incumbent" = 19,"Democratic Incumbent" = 17,"Difference" = 15)) + 
  scale_linetype_manual(values = c("Republican Incumbent" = 1,"Democratic Incumbent" = 1,"Difference" = 1)) + 
	annotate(x = 1.5,y=-0.37,geom = "text",label="Republican candidate does better",col="red",hjust=0,size=5) +	
	annotate(x = 1.5,y=-0.38,xend=1.5,yend=-.4,geom = "segment",arrow=arrow(type = "closed",angle = 20),col="red") +	
	annotate(x = 1.5,y=0.37,geom = "text",label="Democratic candidate does better",col="blue",hjust=1,size=5) +	
	annotate(x = 1.5,y=0.38,xend=1.5,yend=.4,geom = "segment",arrow=arrow(type = "closed",angle = 20),col="blue") +	
	geom_hline(yintercept = 0,size=.5,colour="black",linetype="dotted") +
  theme_bw() +
  coord_flip() + 
  theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black")) +  
  # theme(axis.title.y = element_blank()) +
  theme(axis.text.x = element_text(size=15)) + 
  theme(axis.title.x = element_text(size=20)) + 
  theme(legend.position = "none")

ggsave("Figures/coefplot_inc_nopres_fedstate.pdf",coef_plot_nopres_fedstate,width=11,height=6)


#--------------------------------------------------#
#### Figure D-5: Coefplot for level VS + lag DV ####
#--------------------------------------------------#

pres_lagDV <- felm(pres_demshare ~ wages_perworker_real_delta*pres_dem_control + pres_demshare_lag
									 | fips + state_year |0| fips, 
									 data=data_analysis[data_analysis$population_2010 > 20000,])
sen_lagDV <- felm(sen_demshare ~ wages_perworker_real_delta*pres_dem_control + sen_demshare_lag
									| fips + state_year |0| fips, 
									data=data_analysis[data_analysis$population_2010 > 20000,])
house_lagDV <- felm(house_demshare ~ wages_perworker_real_delta*pres_dem_control + house_demshare_lag
										| fips + state_year |0| fips, 
										data=data_analysis[data_analysis$population_2010 > 20000,])
federal_lagDV <- felm(partisanship_federal ~ wages_perworker_real_delta*pres_dem_control + partisanship_federal_lag
											| fips + state_year |0| fips, 
											data=data_analysis[data_analysis$population_2010 > 20000,])
gov_lagDV <- felm(gov_demshare ~ wages_perworker_real_delta*pres_dem_control + gov_demshare_lag
									| fips + state_year |0| fips, 
									data=data_analysis[data_analysis$population_2010 > 20000,])
stateexec_lagDV <- felm(stateoffice_demshare ~ wages_perworker_real_delta*pres_dem_control + stateoffice_demshare_lag
												| fips + state_year |0| fips, 
												data=data_analysis[data_analysis$population_2010 > 20000,])
sldl_lagDV <- felm(sldl_demshare ~ wages_perworker_real_delta*pres_dem_control + sldl_demshare_lag
									 | fips + state_year |0| fips, 
									 data=data_analysis[data_analysis$population_2010 > 20000,])
sldu_lagDV <- felm(sldu_demshare ~ wages_perworker_real_delta*pres_dem_control + sldu_demshare_lag
									 | fips + state_year |0| fips, 
									 data=data_analysis[data_analysis$population_2010 > 20000,])
state_lagDV <- felm(partisanship_state ~ wages_perworker_real_delta*pres_dem_control + partisanship_state_lag
										| fips + state_year |0| fips, 
										data=data_analysis[data_analysis$population_2010 > 20000,])
county_lagDV <- felm(countyleg_avg_demshare ~ wages_perworker_real_delta*pres_dem_control + countyleg_avg_demshare_lag
										 | fips + state_year |0| fips, 
										 data=data_analysis[data_analysis$population_2010 > 20000,])
mayor_lagDV <- felm(mayor_demshare ~ wages_perworker_real_delta*pres_dem_control + mayor_demshare_lag
										| fips + state_year |0| fips, 
										data=data_analysis[data_analysis$population_2010 > 20000,])


coefs_for_plot <- data.frame(
	group = c(rep(c("President","Senate","House","Federal Avg","Governor","State Execs","State House","State Avg","County","Mayor"),each=3)),
	estimate = c(summary(pres_lagDV)$coefficients[1,1],
							 summary(pres_lagDV)$coefficients[1,1]+summary(pres_lagDV)$coefficients[4,1],
							 summary(pres_lagDV)$coefficients[4,1],
							 summary(sen_lagDV)$coefficients[1,1],
							 summary(sen_lagDV)$coefficients[1,1]+summary(sen_lagDV)$coefficients[4,1],
							 summary(sen_lagDV)$coefficients[4,1],
							 summary(house_lagDV)$coefficients[1,1],
							 summary(house_lagDV)$coefficients[1,1]+summary(house_lagDV)$coefficients[4,1],
							 summary(house_lagDV)$coefficients[4,1],
							 summary(federal_lagDV)$coefficients[1,1],
							 summary(federal_lagDV)$coefficients[1,1]+summary(federal_lagDV)$coefficients[4,1],
							 summary(federal_lagDV)$coefficients[4,1],
							 
							 summary(gov_lagDV)$coefficients[1,1],
							 summary(gov_lagDV)$coefficients[1,1]+summary(gov_lagDV)$coefficients[4,1],
							 summary(gov_lagDV)$coefficients[4,1],
							 summary(stateexec_lagDV)$coefficients[1,1],
							 summary(stateexec_lagDV)$coefficients[1,1]+summary(stateexec_lagDV)$coefficients[4,1],
							 summary(stateexec_lagDV)$coefficients[4,1],
							 summary(sldl_lagDV)$coefficients[1,1],
							 summary(sldl_lagDV)$coefficients[1,1]+summary(sldl_lagDV)$coefficients[4,1],
							 summary(sldl_lagDV)$coefficients[4,1],
							 summary(state_lagDV)$coefficients[1,1],
							 summary(state_lagDV)$coefficients[1,1]+summary(state_lagDV)$coefficients[4,1],
							 summary(state_lagDV)$coefficients[4,1],
							 
							 summary(county_lagDV)$coefficients[1,1],
							 summary(county_lagDV)$coefficients[1,1]+summary(county_lagDV)$coefficients[4,1],
							 summary(county_lagDV)$coefficients[4,1],
							 
							 summary(mayor_lagDV)$coefficients[1,1],
							 summary(mayor_lagDV)$coefficients[1,1]+summary(mayor_lagDV)$coefficients[4,1],
							 summary(mayor_lagDV)$coefficients[4,1]
	),
	se = c(summary(pres_lagDV)$coefficients[1,2],
				 sqrt(summary(pres_lagDV)$coefficients[1,2]^2+summary(pres_lagDV)$coefficients[4,2]^2 + 2*pres_lagDV$vcv[1,4]),
				 summary(pres_lagDV)$coefficients[4,2],
				 summary(sen_lagDV)$coefficients[1,2],
				 sqrt(summary(sen_lagDV)$coefficients[1,2]^2+summary(sen_lagDV)$coefficients[4,2]^2 + 2*sen_lagDV$vcv[1,4]),
				 summary(sen_lagDV)$coefficients[4,2],
				 summary(house_lagDV)$coefficients[1,2],
				 sqrt(summary(house_lagDV)$coefficients[1,2]^2+summary(house_lagDV)$coefficients[4,2]^2 + 2*house_lagDV$vcv[1,4]),
				 summary(house_lagDV)$coefficients[4,2],
				 summary(federal_lagDV)$coefficients[1,2],
				 sqrt(summary(federal_lagDV)$coefficients[1,2]^2+summary(federal_lagDV)$coefficients[4,2]^2 + 2*federal_lagDV$vcv[1,4]),
				 summary(federal_lagDV)$coefficients[4,2],
				 
				 summary(gov_lagDV)$coefficients[1,2],
				 sqrt(summary(gov_lagDV)$coefficients[1,2]^2+summary(gov_lagDV)$coefficients[4,2]^2 + 2*gov_lagDV$vcv[1,4]),
				 summary(gov_lagDV)$coefficients[4,2],
				 summary(stateexec_lagDV)$coefficients[1,2],
				 sqrt(summary(stateexec_lagDV)$coefficients[1,2]^2+summary(stateexec_lagDV)$coefficients[4,2]^2 + 2*stateexec_lagDV$vcv[1,4]),
				 summary(stateexec_lagDV)$coefficients[4,2],
				 summary(sldl_lagDV)$coefficients[1,2],
				 sqrt(summary(sldl_lagDV)$coefficients[1,2]^2+summary(sldl_lagDV)$coefficients[4,2]^2 + 2*sldl_lagDV$vcv[1,4]),
				 summary(sldl_lagDV)$coefficients[4,2],
				 summary(state_lagDV)$coefficients[1,2],
				 sqrt(summary(state_lagDV)$coefficients[1,2]^2+summary(state_lagDV)$coefficients[4,2]^2 + 2*state_lagDV$vcv[1,4]),
				 summary(state_lagDV)$coefficients[4,2],
				 
				 summary(county_lagDV)$coefficients[1,2],
				 sqrt(summary(county_lagDV)$coefficients[1,2]^2+summary(county_lagDV)$coefficients[4,2]^2 + 2*county_lagDV$vcv[1,4]),
				 summary(county_lagDV)$coefficients[4,2],
				 summary(mayor_lagDV)$coefficients[1,2],
				 sqrt(summary(mayor_lagDV)$coefficients[1,2]^2+summary(mayor_lagDV)$coefficients[4,2]^2 + 2*mayor_lagDV$vcv[1,4]),
				 summary(mayor_lagDV)$coefficients[4,2]
	)
)

coefs_for_plot$party <- factor(rep(c("Republican","Democrat","Difference"),10),levels = c("Democrat","Republican","Difference"),ordered=T)
coefs_for_plot$order <- c(10.15,10,9.85,9.15,9,8.85,8.15,8,7.85,7.15,7,6.85,6.15,6,5.85,5.15,5,4.85,4.15,4,3.85,3.15,3,2.85,2.15,2,1.85,1.15,1,0.85)
coefs_for_plot$fontface <- rep(c("plain","plain","plain","bold.italic","plain","plain","plain","bold.italic","plain","plain"),each=3)


coef_plot_all <- ggplot(data = filter(coefs_for_plot,order>2.5), aes(y = estimate, x = order,color=party)) +
	geom_errorbar(data = filter(coefs_for_plot,order>2.5), lwd=1, width=0.0, aes(x = order, 
																																							 ymin = estimate + qnorm(0.025)*se, 
																																							 ymax = estimate + qnorm(0.975)*se,
																																							 col=party)
	) +
	geom_point(size = 3.75,aes(shape=party)) + 
	geom_text(data = filter(coefs_for_plot,group=="President"),
						aes(y = estimate + qnorm(0.975)*se, x=order,label=party),hjust=-0.15) + 
	scale_y_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare", limits = c(-0.3,0.42),breaks = seq(-0.4,0.4,.1)) +
	scale_x_continuous("",breaks=c(10:1),labels=c("President","Senate","House","Federal Average","Governor","Downballot\nState Offices","State House","State Average","County","Local")) +
	scale_color_manual(breaks = c("Democrat","Republican","Difference"),values=c("blue","red","black")) + 
  scale_shape_manual(values = c("Republican" = 19,"Democrat" = 17,"Difference" = 15)) + 
  geom_hline(yintercept = 0,size=.5,colour="black",linetype="dotted") +
	theme_bw() +
	coord_flip() + 
	theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black",
																	 face=filter(coefs_for_plot,order>2.5 & party=="Democrat")$fontface)) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=15)) + 
	theme(axis.title.x = element_text(size=20)) + 
	theme(legend.position = "none")

ggsave("Figures/coefplot_lagDV_all.pdf",coef_plot_all,width=11,height=6)


coef_plot_local <- ggplot(data = filter(coefs_for_plot,order<2.5), aes(y = estimate, x = order,color=party)) +
	geom_errorbar(data = filter(coefs_for_plot,order<2.5), lwd=1, width=0.0, aes(x = order, 
																																							 ymin = estimate + qnorm(0.025)*se, 
																																							 ymax = estimate + qnorm(0.975)*se,
																																							 col=party)
	) +
	geom_point(size = 3.75,aes(shape=party)) + 
	geom_text(data = filter(coefs_for_plot,group=="County"),
						aes(y = estimate + qnorm(0.975)*se, x=order,label=party),hjust=-0.15) + 
	scale_y_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare",limits=c(-3,4.5),breaks=seq(-3,5,0.5)) +
	scale_x_continuous("",breaks=c(10:1),labels=c("President","Senate","House","Federal Avg","Governor","Downballot\nState Offices","State House","State Avg","County\nLegislature","Mayor")) +
	scale_color_manual(breaks = c("Democrat","Republican","Difference"),values=c("blue","red","black")) + 
  scale_shape_manual(values = c("Republican" = 19,"Democrat" = 17,"Difference" = 15)) + 
  geom_hline(yintercept = 0,size=.5,colour="black",linetype="dotted") +
	theme_bw() +
	coord_flip() + 
	theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black")) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=15)) + 
	theme(axis.title.x = element_text(size=20)) + 
	theme(legend.position = "none")

ggsave("Figures/coefplot_lagDV_local.pdf",coef_plot_local,width=11,height=3)


#### without FEs 
pres_lagDV_nofes <- felm(pres_demshare ~ wages_perworker_real_delta*pres_dem_control + pres_demshare_lag
                         | state_year |0| fips, 
                         data=data_analysis[data_analysis$population_2010 > 20000,])
sen_lagDV_nofes <- felm(sen_demshare ~ wages_perworker_real_delta*pres_dem_control + sen_demshare_lag
                        | state_year |0| fips, 
                        data=data_analysis[data_analysis$population_2010 > 20000,])
house_lagDV_nofes <- felm(house_demshare ~ wages_perworker_real_delta*pres_dem_control + house_demshare_lag
                          | state_year |0| fips, 
                          data=data_analysis[data_analysis$population_2010 > 20000,])
federal_lagDV_nofes <- felm(partisanship_federal ~ wages_perworker_real_delta*pres_dem_control + partisanship_federal_lag
                            | state_year |0| fips, 
                            data=data_analysis[data_analysis$population_2010 > 20000,])
gov_lagDV_nofes <- felm(gov_demshare ~ wages_perworker_real_delta*pres_dem_control + gov_demshare_lag
                        | state_year |0| fips, 
                        data=data_analysis[data_analysis$population_2010 > 20000,])
stateexec_lagDV_nofes <- felm(stateoffice_demshare ~ wages_perworker_real_delta*pres_dem_control + stateoffice_demshare_lag
                              | state_year |0| fips, 
                              data=data_analysis[data_analysis$population_2010 > 20000,])
sldl_lagDV_nofes <- felm(sldl_demshare ~ wages_perworker_real_delta*pres_dem_control + sldl_demshare_lag
                         | state_year |0| fips, 
                         data=data_analysis[data_analysis$population_2010 > 20000,])
sldu_lagDV_nofes <- felm(sldu_demshare ~ wages_perworker_real_delta*pres_dem_control + sldu_demshare_lag
                         | state_year |0| fips, 
                         data=data_analysis[data_analysis$population_2010 > 20000,])
state_lagDV_nofes <- felm(partisanship_state ~ wages_perworker_real_delta*pres_dem_control + partisanship_state_lag
                          | state_year |0| fips, 
                          data=data_analysis[data_analysis$population_2010 > 20000,])
county_lagDV_nofes <- felm(countyleg_avg_demshare ~ wages_perworker_real_delta*pres_dem_control + countyleg_avg_demshare_lag
                           | state_year |0| fips, 
                           data=data_analysis[data_analysis$population_2010 > 20000,])
mayor_lagDV_nofes <- felm(mayor_demshare ~ wages_perworker_real_delta*pres_dem_control + mayor_demshare_lag
                          |  state_year |0| fips, 
                          data=data_analysis[data_analysis$population_2010 > 20000,])


coefs_for_plot <- data.frame(
  group = c(rep(c("President","Senate","House","Federal Avg","Governor","State Execs","State House","State Avg","County","Mayor"),each=3)),
  estimate = c(summary(pres_lagDV_nofes)$coefficients[1,1],
               summary(pres_lagDV_nofes)$coefficients[1,1]+summary(pres_lagDV_nofes)$coefficients[4,1],
               summary(pres_lagDV_nofes)$coefficients[4,1],
               summary(sen_lagDV_nofes)$coefficients[1,1],
               summary(sen_lagDV_nofes)$coefficients[1,1]+summary(sen_lagDV_nofes)$coefficients[4,1],
               summary(sen_lagDV_nofes)$coefficients[4,1],
               summary(house_lagDV_nofes)$coefficients[1,1],
               summary(house_lagDV_nofes)$coefficients[1,1]+summary(house_lagDV_nofes)$coefficients[4,1],
               summary(house_lagDV_nofes)$coefficients[4,1],
               summary(federal_lagDV_nofes)$coefficients[1,1],
               summary(federal_lagDV_nofes)$coefficients[1,1]+summary(federal_lagDV_nofes)$coefficients[4,1],
               summary(federal_lagDV_nofes)$coefficients[4,1],
               
               summary(gov_lagDV_nofes)$coefficients[1,1],
               summary(gov_lagDV_nofes)$coefficients[1,1]+summary(gov_lagDV_nofes)$coefficients[4,1],
               summary(gov_lagDV_nofes)$coefficients[4,1],
               summary(stateexec_lagDV_nofes)$coefficients[1,1],
               summary(stateexec_lagDV_nofes)$coefficients[1,1]+summary(stateexec_lagDV_nofes)$coefficients[4,1],
               summary(stateexec_lagDV_nofes)$coefficients[4,1],
               summary(sldl_lagDV_nofes)$coefficients[1,1],
               summary(sldl_lagDV_nofes)$coefficients[1,1]+summary(sldl_lagDV_nofes)$coefficients[4,1],
               summary(sldl_lagDV_nofes)$coefficients[4,1],
               summary(state_lagDV_nofes)$coefficients[1,1],
               summary(state_lagDV_nofes)$coefficients[1,1]+summary(state_lagDV_nofes)$coefficients[4,1],
               summary(state_lagDV_nofes)$coefficients[4,1],
               
               summary(county_lagDV_nofes)$coefficients[1,1],
               summary(county_lagDV_nofes)$coefficients[1,1]+summary(county_lagDV_nofes)$coefficients[4,1],
               summary(county_lagDV_nofes)$coefficients[4,1],
               
               summary(mayor_lagDV_nofes)$coefficients[1,1],
               summary(mayor_lagDV_nofes)$coefficients[1,1]+summary(mayor_lagDV_nofes)$coefficients[4,1],
               summary(mayor_lagDV_nofes)$coefficients[4,1]
  ),
  se = c(summary(pres_lagDV_nofes)$coefficients[1,2],
         sqrt(summary(pres_lagDV_nofes)$coefficients[1,2]^2+summary(pres_lagDV_nofes)$coefficients[4,2]^2 + 2*pres_lagDV_nofes$vcv[1,4]),
         summary(pres_lagDV_nofes)$coefficients[4,2],
         summary(sen_lagDV_nofes)$coefficients[1,2],
         sqrt(summary(sen_lagDV_nofes)$coefficients[1,2]^2+summary(sen_lagDV_nofes)$coefficients[4,2]^2 + 2*sen_lagDV_nofes$vcv[1,4]),
         summary(sen_lagDV_nofes)$coefficients[4,2],
         summary(house_lagDV_nofes)$coefficients[1,2],
         sqrt(summary(house_lagDV_nofes)$coefficients[1,2]^2+summary(house_lagDV_nofes)$coefficients[4,2]^2 + 2*house_lagDV_nofes$vcv[1,4]),
         summary(house_lagDV_nofes)$coefficients[4,2],
         summary(federal_lagDV_nofes)$coefficients[1,2],
         sqrt(summary(federal_lagDV_nofes)$coefficients[1,2]^2+summary(federal_lagDV_nofes)$coefficients[4,2]^2 + 2*federal_lagDV_nofes$vcv[1,4]),
         summary(federal_lagDV_nofes)$coefficients[4,2],
         
         summary(gov_lagDV_nofes)$coefficients[1,2],
         sqrt(summary(gov_lagDV_nofes)$coefficients[1,2]^2+summary(gov_lagDV_nofes)$coefficients[4,2]^2 + 2*gov_lagDV_nofes$vcv[1,4]),
         summary(gov_lagDV_nofes)$coefficients[4,2],
         summary(stateexec_lagDV_nofes)$coefficients[1,2],
         sqrt(summary(stateexec_lagDV_nofes)$coefficients[1,2]^2+summary(stateexec_lagDV_nofes)$coefficients[4,2]^2 + 2*stateexec_lagDV_nofes$vcv[1,4]),
         summary(stateexec_lagDV_nofes)$coefficients[4,2],
         summary(sldl_lagDV_nofes)$coefficients[1,2],
         sqrt(summary(sldl_lagDV_nofes)$coefficients[1,2]^2+summary(sldl_lagDV_nofes)$coefficients[4,2]^2 + 2*sldl_lagDV_nofes$vcv[1,4]),
         summary(sldl_lagDV_nofes)$coefficients[4,2],
         summary(state_lagDV_nofes)$coefficients[1,2],
         sqrt(summary(state_lagDV_nofes)$coefficients[1,2]^2+summary(state_lagDV_nofes)$coefficients[4,2]^2 + 2*state_lagDV_nofes$vcv[1,4]),
         summary(state_lagDV_nofes)$coefficients[4,2],
         
         summary(county_lagDV_nofes)$coefficients[1,2],
         sqrt(summary(county_lagDV_nofes)$coefficients[1,2]^2+summary(county_lagDV_nofes)$coefficients[4,2]^2 + 2*county_lagDV_nofes$vcv[1,4]),
         summary(county_lagDV_nofes)$coefficients[4,2],
         summary(mayor_lagDV_nofes)$coefficients[1,2],
         sqrt(summary(mayor_lagDV_nofes)$coefficients[1,2]^2+summary(mayor_lagDV_nofes)$coefficients[4,2]^2 + 2*mayor_lagDV_nofes$vcv[1,4]),
         summary(mayor_lagDV_nofes)$coefficients[4,2]
  )
)

coefs_for_plot$party <- factor(rep(c("Republican","Democrat","Difference"),10),levels = c("Democrat","Republican","Difference"),ordered=T)
coefs_for_plot$order <- c(10.15,10,9.85,9.15,9,8.85,8.15,8,7.85,7.15,7,6.85,6.15,6,5.85,5.15,5,4.85,4.15,4,3.85,3.15,3,2.85,2.15,2,1.85,1.15,1,0.85)
coefs_for_plot$fontface <- rep(c("plain","plain","plain","bold.italic","plain","plain","plain","bold.italic","plain","plain"),each=3)


coef_plot_all <- ggplot(data = filter(coefs_for_plot,order>2.5), aes(y = estimate, x = order,color=party)) +
  geom_errorbar(data = filter(coefs_for_plot,order>2.5), lwd=1, width=0.0, aes(x = order, 
                                                                               ymin = estimate + qnorm(0.025)*se, 
                                                                               ymax = estimate + qnorm(0.975)*se,
                                                                               col=party)
  ) +
  geom_point(size = 3.75,aes(shape=party)) + 
  geom_text(data = filter(coefs_for_plot,group=="President"),
            aes(y = estimate + qnorm(0.975)*se, x=order,label=party),hjust=-0.15) + 
  scale_y_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare,\nNo County-Fixed Effects", limits = c(-0.3,0.42),breaks = seq(-0.4,0.4,.1)) +
  scale_x_continuous("",breaks=c(10:1),labels=c("President","Senate","House","Federal Average","Governor","Downballot\nState Offices","State House","State Average","County","Local")) +
  scale_color_manual(breaks = c("Democrat","Republican","Difference"),values=c("blue","red","black")) + 
  scale_shape_manual(values = c("Republican" = 19,"Democrat" = 17,"Difference" = 15)) + 
  geom_hline(yintercept = 0,size=.5,colour="black",linetype="dotted") +
  theme_bw() +
  coord_flip() + 
  theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black",
                                   face=filter(coefs_for_plot,order>2.5 & party=="Democrat")$fontface)) +  
  # theme(axis.title.y = element_blank()) +
  theme(axis.text.x = element_text(size=15)) + 
  theme(axis.title.x = element_text(size=20)) + 
  theme(legend.position = "none")

ggsave("Figures/coefplot_lagDV_nofes_all.pdf",coef_plot_all,width=11,height=6.5)


#----------------------------------------------#
#### Appendix H: Pre- and Post-1990 Effects ####
#----------------------------------------------#
pres_pre1990 <- felm(pres_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
										 | fips + state_year |0| fips, 
										 data=filter(data_analysis, population_2010 > 20000 & year<1990))
sen_pre1990 <- felm(sen_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
										| fips + state_year |0| fips, 
										data=filter(data_analysis, population_2010 > 20000 & year<1990))
house_pre1990 <- felm(house_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
											| fips + state_year |0| fips, 
											data=filter(data_analysis, population_2010 > 20000 & year<1990))
federal_pre1990 <- felm(partisanship_federal_delta ~ wages_perworker_real_delta*pres_dem_control
												| fips + state_year |0| fips, 
												data=filter(data_analysis, population_2010 > 20000 & year<1990))
gov_pre1990 <- felm(gov_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
										| fips + state_year |0| fips, 
										data=filter(data_analysis, population_2010 > 20000 & year<1990))
stateexec_pre1990 <- felm(stateoffice_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
													| fips + state_year |0| fips, 
													data=filter(data_analysis, population_2010 > 20000 & year<1990))
sldl_pre1990 <- felm(sldl_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
										 | fips + state_year |0| fips, 
										 data=filter(data_analysis, population_2010 > 20000 & year<1990))
sldu_pre1990 <- felm(sldu_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
										 | fips + state_year |0| fips, 
										 data=filter(data_analysis, population_2010 > 20000 & year<1990))
state_pre1990 <- felm(partisanship_state_delta ~ wages_perworker_real_delta*pres_dem_control
											| fips + state_year |0| fips, 
											data=filter(data_analysis, population_2010 > 20000 & year<1990))
county_pre1990 <- felm(countyleg_avg_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
											 | fips + state_year |0| fips, 
											 data=filter(data_analysis, population_2010 > 20000 & year<1990))
mayor_pre1990 <- felm(mayor_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
											| fips + state_year |0| fips, 
											data=filter(data_analysis, population_2010 > 20000 & year<1990))

coefs_for_plot <- data.frame(
	group = c(rep(c("President","Senate","House","Federal Avg","Governor","State Execs","State House","State Avg","County","Mayor"),each=3)),
	estimate = c(summary(pres_pre1990)$coefficients[1,1],
							 summary(pres_pre1990)$coefficients[1,1]+summary(pres_pre1990)$coefficients[3,1],
							 summary(pres_pre1990)$coefficients[3,1],
							 summary(sen_pre1990)$coefficients[1,1],
							 summary(sen_pre1990)$coefficients[1,1]+summary(sen_pre1990)$coefficients[3,1],
							 summary(sen_pre1990)$coefficients[3,1],
							 summary(house_pre1990)$coefficients[1,1],
							 summary(house_pre1990)$coefficients[1,1]+summary(house_pre1990)$coefficients[3,1],
							 summary(house_pre1990)$coefficients[3,1],
							 summary(federal_pre1990)$coefficients[1,1],
							 summary(federal_pre1990)$coefficients[1,1]+summary(federal_pre1990)$coefficients[3,1],
							 summary(federal_pre1990)$coefficients[3,1],
							 
							 summary(gov_pre1990)$coefficients[1,1],
							 summary(gov_pre1990)$coefficients[1,1]+summary(gov_pre1990)$coefficients[3,1],
							 summary(gov_pre1990)$coefficients[3,1],
							 summary(stateexec_pre1990)$coefficients[1,1],
							 summary(stateexec_pre1990)$coefficients[1,1]+summary(stateexec_pre1990)$coefficients[3,1],
							 summary(stateexec_pre1990)$coefficients[3,1],
							 summary(sldl_pre1990)$coefficients[1,1],
							 summary(sldl_pre1990)$coefficients[1,1]+summary(sldl_pre1990)$coefficients[3,1],
							 summary(sldl_pre1990)$coefficients[3,1],
							 summary(state_pre1990)$coefficients[1,1],
							 summary(state_pre1990)$coefficients[1,1]+summary(state_pre1990)$coefficients[3,1],
							 summary(state_pre1990)$coefficients[3,1],
							 
							 summary(county_pre1990)$coefficients[1,1],
							 summary(county_pre1990)$coefficients[1,1]+summary(county_pre1990)$coefficients[3,1],
							 summary(county_pre1990)$coefficients[3,1],
							 
							 summary(mayor_pre1990)$coefficients[1,1],
							 summary(mayor_pre1990)$coefficients[1,1]+summary(mayor_pre1990)$coefficients[3,1],
							 summary(mayor_pre1990)$coefficients[3,1]
	),
	se = c(summary(pres_pre1990)$coefficients[1,2],
				 sqrt(summary(pres_pre1990)$coefficients[1,2]^2+summary(pres_pre1990)$coefficients[3,2]^2 + 2*pres_pre1990$vcv[1,3]),
				 summary(pres_pre1990)$coefficients[3,2],
				 summary(sen_pre1990)$coefficients[1,2],
				 sqrt(summary(sen_pre1990)$coefficients[1,2]^2+summary(sen_pre1990)$coefficients[3,2]^2 + 2*sen_pre1990$vcv[1,3]),
				 summary(sen_pre1990)$coefficients[3,2],
				 summary(house_pre1990)$coefficients[1,2],
				 sqrt(summary(house_pre1990)$coefficients[1,2]^2+summary(house_pre1990)$coefficients[3,2]^2 + 2*house_pre1990$vcv[1,3]),
				 summary(house_pre1990)$coefficients[3,2],
				 summary(federal_pre1990)$coefficients[1,2],
				 sqrt(summary(federal_pre1990)$coefficients[1,2]^2+summary(federal_pre1990)$coefficients[3,2]^2 + 2*federal_pre1990$vcv[1,3]),
				 summary(federal_pre1990)$coefficients[3,2],
				 
				 summary(gov_pre1990)$coefficients[1,2],
				 sqrt(summary(gov_pre1990)$coefficients[1,2]^2+summary(gov_pre1990)$coefficients[3,2]^2 + 2*gov_pre1990$vcv[1,3]),
				 summary(gov_pre1990)$coefficients[3,2],
				 summary(stateexec_pre1990)$coefficients[1,2],
				 sqrt(summary(stateexec_pre1990)$coefficients[1,2]^2+summary(stateexec_pre1990)$coefficients[3,2]^2 + 2*stateexec_pre1990$vcv[1,3]),
				 summary(stateexec_pre1990)$coefficients[3,2],
				 summary(sldl_pre1990)$coefficients[1,2],
				 sqrt(summary(sldl_pre1990)$coefficients[1,2]^2+summary(sldl_pre1990)$coefficients[3,2]^2 + 2*sldl_pre1990$vcv[1,3]),
				 summary(sldl_pre1990)$coefficients[3,2],
				 summary(state_pre1990)$coefficients[1,2],
				 sqrt(summary(state_pre1990)$coefficients[1,2]^2+summary(state_pre1990)$coefficients[3,2]^2 + 2*state_pre1990$vcv[1,3]),
				 summary(state_pre1990)$coefficients[3,2],
				 
				 summary(county_pre1990)$coefficients[1,2],
				 sqrt(summary(county_pre1990)$coefficients[1,2]^2+summary(county_pre1990)$coefficients[3,2]^2 + 2*county_pre1990$vcv[1,3]),
				 summary(county_pre1990)$coefficients[3,2],
				 summary(mayor_pre1990)$coefficients[1,2],
				 sqrt(summary(mayor_pre1990)$coefficients[1,2]^2+summary(mayor_pre1990)$coefficients[3,2]^2 + 2*mayor_pre1990$vcv[1,3]),
				 summary(mayor_pre1990)$coefficients[3,2]
	)
)

coefs_for_plot$party <- factor(rep(c("Republican","Democrat","Difference"),10),levels = c("Democrat","Republican","Difference"),ordered=T)
coefs_for_plot$order <- c(10.15,10,9.85,9.15,9,8.85,8.15,8,7.85,7.15,7,6.85,6.15,6,5.85,5.15,5,4.85,4.15,4,3.85,3.15,3,2.85,2.15,2,1.85,1.15,1,0.85)
coefs_for_plot$fontface <- rep(c("plain","plain","plain","bold.italic","plain","plain","plain","bold.italic","plain","plain"),each=3)

coef_plot_all <- ggplot(data = filter(coefs_for_plot,order>2.5), aes(y = estimate, x = order,color=party)) +
	geom_errorbar(data = filter(coefs_for_plot,order>2.5), lwd=1, width=0.0, aes(x = order, 
																																							 ymin = estimate + qnorm(0.025)*se, 
																																							 ymax = estimate + qnorm(0.975)*se,
																																							 col=party)
	) +
	geom_point(size = 3.75,aes(shape=party)) + 
	geom_text(data = filter(coefs_for_plot,group=="President"),
						aes(y = estimate + qnorm(0.975)*se, x=order,label=party),hjust=-0.15) + 
	scale_y_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare", limits = c(-0.7,0.86),breaks = seq(-0.8,1,.2)) +
	scale_x_continuous("",breaks=c(10:1),labels=c("President","Senate","House","Federal Average","Governor","Downballot\nState Offices","State House","State Average","County","Local")) +
	scale_color_manual(breaks = c("Democrat","Republican","Difference"),values=c("blue","red","black")) + 
	scale_shape_manual(values = c("Republican" = 19,"Democrat" = 17,"Difference" = 15)) + 
	geom_hline(yintercept = 0,size=.5,colour="black",linetype="dotted") +
	theme_bw() +
	coord_flip() + 
	theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black",
																	 face=filter(coefs_for_plot,order>2.5 & party=="Democrat")$fontface)) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=15)) + 
	theme(axis.title.x = element_text(size=20)) + 
	theme(legend.position = "none")

ggsave("Figures/coefplot_pre1990_all.pdf",coef_plot_all,width=11,height=6)

coef_plot_federal <- ggplot(data = filter(coefs_for_plot,order>6.5), aes(y = estimate, x = order,color=party)) +
	geom_errorbar(data = filter(coefs_for_plot,order>6.5), lwd=1, width=0.0, aes(x = order, 
																																							 ymin = estimate + qnorm(0.025)*se, 
																																							 ymax = estimate + qnorm(0.975)*se,
																																							 col=party)
	) +
	geom_point(size = 3.75,aes(shape=party)) + 
	geom_text(data = filter(coefs_for_plot,group=="President"),
						aes(y = estimate + qnorm(0.975)*se, x=order,label=party),hjust=-0.15) + 
	scale_y_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare", limits = c(-0.3,0.57),breaks = seq(-0.4,0.6,.1)) +
	scale_x_continuous("",breaks=c(10:2),labels=c("President","Senate","House","Federal Average","Governor","Downballot\nState Offices","State House","State Avg","County")) +
	scale_color_manual(breaks = c("Democrat","Republican","Difference"),values=c("blue","red","black")) + 
	scale_shape_manual(values = c("Republican" = 19,"Democrat" = 17,"Difference" = 15)) + 
	annotate(x = 6.5,y=-0.27,geom = "text",label="Republican candidate does better",col="red",hjust=0,size=5) +	
	annotate(x = 6.5,y=-0.28,xend=6.5,yend=-.3,geom = "segment",arrow=arrow(type = "closed",angle = 20),col="red") +	
	annotate(x = 6.5,y=0.37,geom = "text",label="Democratic candidate does better",col="blue",hjust=1,size=5) +	
	annotate(x = 6.5,y=0.38,xend=6.5,yend=.4,geom = "segment",arrow=arrow(type = "closed",angle = 20),col="blue") +		geom_hline(yintercept = 0,size=.5,colour="black",linetype="dotted") +
	theme_bw() +
	coord_flip() + 
	theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black",
																	 face=filter(coefs_for_plot,order>2.5 & party=="Democrat")$fontface)) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=15)) + 
	theme(axis.title.x = element_text(size=20)) + 
	theme(legend.position = "none")

ggsave("Figures/coefplot_pre1990_federal.pdf",coef_plot_federal,width=11,height=6)



## State Offices:
coef_plot_state <- ggplot(data = filter(coefs_for_plot,order<6.5 & order>2.5), aes(y = estimate, x = order,color=party)) +
	geom_errorbar(data = filter(coefs_for_plot,order<6.5 & order>2.5), lwd=1, width=0.0, aes(x = order, 
																																													 ymin = estimate + qnorm(0.025)*se, 
																																													 ymax = estimate + qnorm(0.975)*se,
																																													 col=party)
	) +
	geom_point(size = 3.75,aes(shape=party)) + 
	geom_text(data = filter(coefs_for_plot,group=="Governor"),
						aes(y = estimate + qnorm(0.975)*se, x=order,label=party),hjust=-0.15) + 
	scale_y_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare",limits=c(-0.45,0.86),breaks=seq(-0.8,1,0.2)) +
	scale_x_continuous("",breaks=c(10:2),labels=c("President","Senate","House","Federal Avg","Governor","Downballot\nState Offices","State House","State Average","County")) +
	scale_color_manual(breaks = c("Democrat","Republican","Difference"),values=c("blue","red","black")) + 
	scale_shape_manual(values = c("Republican" = 19,"Democrat" = 17,"Difference" = 15)) + 
	geom_hline(yintercept = 0,size=.5,colour="black",linetype="dotted") +
	theme_bw() +
	coord_flip() + 
	theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black",
																	 face=filter(coefs_for_plot,order>2.5 & party=="Democrat")$fontface)) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=15)) + 
	theme(axis.title.x = element_text(size=20)) + 
	theme(legend.position = "none")

ggsave("Figures/coefplot_pre1990_state.pdf",coef_plot_state,width=11,height=6)


## Local offices:
coef_plot_local <- ggplot(data = filter(coefs_for_plot,order<2.5), aes(y = estimate, x = order,color=party)) +
	geom_errorbar(data = filter(coefs_for_plot,order<2.5), lwd=1, width=0.0, aes(x = order, 
																																							 ymin = estimate + qnorm(0.025)*se, 
																																							 ymax = estimate + qnorm(0.975)*se,
																																							 col=party)
	) +
	geom_point(size = 3.75,aes(shape=party)) + 
	geom_text(data = filter(coefs_for_plot,group=="County"),
						aes(y = estimate + qnorm(0.975)*se, x=order,label=party),hjust=-0.15) + 
	scale_y_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare",limits=c(-11,25),breaks=seq(-20,26,5)) +
	scale_x_continuous("",breaks=c(10:1),labels=c("President","Senate","House","Federal Avg","Governor","Downballot\nState Offices","State House","State Avg","County\nLegislature","Mayor")) +
	scale_color_manual(breaks = c("Democrat","Republican","Difference"),values=c("blue","red","black")) + 
	scale_shape_manual(values = c("Republican" = 19,"Democrat" = 17,"Difference" = 15)) + 
	geom_hline(yintercept = 0,size=.5,colour="black",linetype="dotted") +
	theme_bw() +
	coord_flip() + 
	theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black")) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=15)) + 
	theme(axis.title.x = element_text(size=20)) + 
	theme(legend.position = "none")

ggsave("Figures/coefplot_pre1990_local.pdf",coef_plot_local,width=11,height=3)


## Post-1990
pres_post1990 <- felm(pres_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
											| fips + state_year |0| fips, 
											data=filter(data_analysis, population_2010 > 20000 & year>=1990))
sen_post1990 <- felm(sen_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
										 | fips + state_year |0| fips, 
										 data=filter(data_analysis, population_2010 > 20000 & year>=1990))
house_post1990 <- felm(house_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
											 | fips + state_year |0| fips, 
											 data=filter(data_analysis, population_2010 > 20000 & year>=1990))
federal_post1990 <- felm(partisanship_federal_delta ~ wages_perworker_real_delta*pres_dem_control
												 | fips + state_year |0| fips, 
												 data=filter(data_analysis, population_2010 > 20000 & year>=1990))
gov_post1990 <- felm(gov_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
										 | fips + state_year |0| fips, 
										 data=filter(data_analysis, population_2010 > 20000 & year>=1990))
stateexec_post1990 <- felm(stateoffice_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
													 | fips + state_year |0| fips, 
													 data=filter(data_analysis, population_2010 > 20000 & year>=1990))
sldl_post1990 <- felm(sldl_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
											| fips + state_year |0| fips, 
											data=filter(data_analysis, population_2010 > 20000 & year>=1990))
sldu_post1990 <- felm(sldu_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
											| fips + state_year |0| fips, 
											data=filter(data_analysis, population_2010 > 20000 & year>=1990))
state_post1990 <- felm(partisanship_state_delta ~ wages_perworker_real_delta*pres_dem_control
											 | fips + state_year |0| fips, 
											 data=filter(data_analysis, population_2010 > 20000 & year>=1990))
county_post1990 <- felm(countyleg_avg_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
												| fips + state_year |0| fips, 
												data=filter(data_analysis, population_2010 > 20000 & year>=1990))
mayor_post1990 <- felm(mayor_demshare_delta ~ wages_perworker_real_delta*pres_dem_control
											 | fips + state_year |0| fips, 
											 data=filter(data_analysis, population_2010 > 20000 & year>=1990))

coefs_for_plot <- data.frame(
	group = c(rep(c("President","Senate","House","Federal Avg","Governor","State Execs","State House","State Avg","County","Mayor"),each=3)),
	estimate = c(summary(pres_post1990)$coefficients[1,1],
							 summary(pres_post1990)$coefficients[1,1]+summary(pres_post1990)$coefficients[3,1],
							 summary(pres_post1990)$coefficients[3,1],
							 summary(sen_post1990)$coefficients[1,1],
							 summary(sen_post1990)$coefficients[1,1]+summary(sen_post1990)$coefficients[3,1],
							 summary(sen_post1990)$coefficients[3,1],
							 summary(house_post1990)$coefficients[1,1],
							 summary(house_post1990)$coefficients[1,1]+summary(house_post1990)$coefficients[3,1],
							 summary(house_post1990)$coefficients[3,1],
							 summary(federal_post1990)$coefficients[1,1],
							 summary(federal_post1990)$coefficients[1,1]+summary(federal_post1990)$coefficients[3,1],
							 summary(federal_post1990)$coefficients[3,1],
							 
							 summary(gov_post1990)$coefficients[1,1],
							 summary(gov_post1990)$coefficients[1,1]+summary(gov_post1990)$coefficients[3,1],
							 summary(gov_post1990)$coefficients[3,1],
							 summary(stateexec_post1990)$coefficients[1,1],
							 summary(stateexec_post1990)$coefficients[1,1]+summary(stateexec_post1990)$coefficients[3,1],
							 summary(stateexec_post1990)$coefficients[3,1],
							 summary(sldl_post1990)$coefficients[1,1],
							 summary(sldl_post1990)$coefficients[1,1]+summary(sldl_post1990)$coefficients[3,1],
							 summary(sldl_post1990)$coefficients[3,1],
							 summary(state_post1990)$coefficients[1,1],
							 summary(state_post1990)$coefficients[1,1]+summary(state_post1990)$coefficients[3,1],
							 summary(state_post1990)$coefficients[3,1],
							 
							 summary(county_post1990)$coefficients[1,1],
							 summary(county_post1990)$coefficients[1,1]+summary(county_post1990)$coefficients[3,1],
							 summary(county_post1990)$coefficients[3,1],
							 
							 summary(mayor_post1990)$coefficients[1,1],
							 summary(mayor_post1990)$coefficients[1,1]+summary(mayor_post1990)$coefficients[3,1],
							 summary(mayor_post1990)$coefficients[3,1]
	),
	se = c(summary(pres_post1990)$coefficients[1,2],
				 sqrt(summary(pres_post1990)$coefficients[1,2]^2+summary(pres_post1990)$coefficients[3,2]^2 + 2*pres_post1990$vcv[1,3]),
				 summary(pres_post1990)$coefficients[3,2],
				 summary(sen_post1990)$coefficients[1,2],
				 sqrt(summary(sen_post1990)$coefficients[1,2]^2+summary(sen_post1990)$coefficients[3,2]^2 + 2*sen_post1990$vcv[1,3]),
				 summary(sen_post1990)$coefficients[3,2],
				 summary(house_post1990)$coefficients[1,2],
				 sqrt(summary(house_post1990)$coefficients[1,2]^2+summary(house_post1990)$coefficients[3,2]^2 + 2*house_post1990$vcv[1,3]),
				 summary(house_post1990)$coefficients[3,2],
				 summary(federal_post1990)$coefficients[1,2],
				 sqrt(summary(federal_post1990)$coefficients[1,2]^2+summary(federal_post1990)$coefficients[3,2]^2 + 2*federal_post1990$vcv[1,3]),
				 summary(federal_post1990)$coefficients[3,2],
				 
				 summary(gov_post1990)$coefficients[1,2],
				 sqrt(summary(gov_post1990)$coefficients[1,2]^2+summary(gov_post1990)$coefficients[3,2]^2 + 2*gov_post1990$vcv[1,3]),
				 summary(gov_post1990)$coefficients[3,2],
				 summary(stateexec_post1990)$coefficients[1,2],
				 sqrt(summary(stateexec_post1990)$coefficients[1,2]^2+summary(stateexec_post1990)$coefficients[3,2]^2 + 2*stateexec_post1990$vcv[1,3]),
				 summary(stateexec_post1990)$coefficients[3,2],
				 summary(sldl_post1990)$coefficients[1,2],
				 sqrt(summary(sldl_post1990)$coefficients[1,2]^2+summary(sldl_post1990)$coefficients[3,2]^2 + 2*sldl_post1990$vcv[1,3]),
				 summary(sldl_post1990)$coefficients[3,2],
				 summary(state_post1990)$coefficients[1,2],
				 sqrt(summary(state_post1990)$coefficients[1,2]^2+summary(state_post1990)$coefficients[3,2]^2 + 2*state_post1990$vcv[1,3]),
				 summary(state_post1990)$coefficients[3,2],
				 
				 summary(county_post1990)$coefficients[1,2],
				 sqrt(summary(county_post1990)$coefficients[1,2]^2+summary(county_post1990)$coefficients[3,2]^2 + 2*county_post1990$vcv[1,3]),
				 summary(county_post1990)$coefficients[3,2],
				 summary(mayor_post1990)$coefficients[1,2],
				 sqrt(summary(mayor_post1990)$coefficients[1,2]^2+summary(mayor_post1990)$coefficients[3,2]^2 + 2*mayor_post1990$vcv[1,3]),
				 summary(mayor_post1990)$coefficients[3,2]
	)
)

coefs_for_plot$party <- factor(rep(c("Republican","Democrat","Difference"),10),levels = c("Democrat","Republican","Difference"),ordered=T)
coefs_for_plot$order <- c(10.15,10,9.85,9.15,9,8.85,8.15,8,7.85,7.15,7,6.85,6.15,6,5.85,5.15,5,4.85,4.15,4,3.85,3.15,3,2.85,2.15,2,1.85,1.15,1,0.85)
coefs_for_plot$fontface <- rep(c("plain","plain","plain","bold.italic","plain","plain","plain","bold.italic","plain","plain"),each=3)

coef_plot_all <- ggplot(data = filter(coefs_for_plot,order>2.5), aes(y = estimate, x = order,color=party)) +
	geom_errorbar(data = filter(coefs_for_plot,order>2.5), lwd=1, width=0.0, aes(x = order, 
																																							 ymin = estimate + qnorm(0.025)*se, 
																																							 ymax = estimate + qnorm(0.975)*se,
																																							 col=party)
	) +
	geom_point(size = 3.75,aes(shape=party)) + 
	geom_text(data = filter(coefs_for_plot,group=="President"),
						aes(y = estimate + qnorm(0.975)*se, x=order,label=party),hjust=-0.15) + 
	scale_y_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare", limits = c(-0.7,0.86),breaks = seq(-0.8,1,.2)) +
	scale_x_continuous("",breaks=c(10:1),labels=c("President","Senate","House","Federal Average","Governor","Downballot\nState Offices","State House","State Average","County","Local")) +
	scale_color_manual(breaks = c("Democrat","Republican","Difference"),values=c("blue","red","black")) + 
	scale_shape_manual(values = c("Republican" = 19,"Democrat" = 17,"Difference" = 15)) + 
	geom_hline(yintercept = 0,size=.5,colour="black",linetype="dotted") +
	theme_bw() +
	coord_flip() + 
	theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black",
																	 face=filter(coefs_for_plot,order>2.5 & party=="Democrat")$fontface)) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=15)) + 
	theme(axis.title.x = element_text(size=20)) + 
	theme(legend.position = "none")

ggsave("Figures/coefplot_post1990_all.pdf",coef_plot_all,width=11,height=6)

coef_plot_federal <- ggplot(data = filter(coefs_for_plot,order>6.5), aes(y = estimate, x = order,color=party)) +
	geom_errorbar(data = filter(coefs_for_plot,order>6.5), lwd=1, width=0.0, aes(x = order, 
																																							 ymin = estimate + qnorm(0.025)*se, 
																																							 ymax = estimate + qnorm(0.975)*se,
																																							 col=party)
	) +
	geom_point(size = 3.75,aes(shape=party)) + 
	geom_text(data = filter(coefs_for_plot,group=="President"),
						aes(y = estimate + qnorm(0.975)*se, x=order,label=party),hjust=-0.15) + 
	scale_y_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare", limits = c(-0.3,0.4),breaks = seq(-0.4,0.4,.1)) +
	scale_x_continuous("",breaks=c(10:2),labels=c("President","Senate","House","Federal Average","Governor","Downballot\nState Offices","State House","State Avg","County")) +
	scale_color_manual(breaks = c("Democrat","Republican","Difference"),values=c("blue","red","black")) + 
	scale_shape_manual(values = c("Republican" = 19,"Democrat" = 17,"Difference" = 15)) + 
	annotate(x = 6.5,y=-0.27,geom = "text",label="Republican candidate does better",col="red",hjust=0,size=5) +	
	annotate(x = 6.5,y=-0.28,xend=6.5,yend=-.3,geom = "segment",arrow=arrow(type = "closed",angle = 20),col="red") +	
	annotate(x = 6.5,y=0.37,geom = "text",label="Democratic candidate does better",col="blue",hjust=1,size=5) +	
	annotate(x = 6.5,y=0.38,xend=6.5,yend=.4,geom = "segment",arrow=arrow(type = "closed",angle = 20),col="blue") +		geom_hline(yintercept = 0,size=.5,colour="black",linetype="dotted") +
	theme_bw() +
	coord_flip() + 
	theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black",
																	 face=filter(coefs_for_plot,order>2.5 & party=="Democrat")$fontface)) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=15)) + 
	theme(axis.title.x = element_text(size=20)) + 
	theme(legend.position = "none")

ggsave("Figures/coefplot_post1990_federal.pdf",coef_plot_federal,width=11,height=6)



## State Offices:
coef_plot_state <- ggplot(data = filter(coefs_for_plot,order<6.5 & order>2.5), aes(y = estimate, x = order,color=party)) +
	geom_errorbar(data = filter(coefs_for_plot,order<6.5 & order>2.5), lwd=1, width=0.0, aes(x = order, 
																																													 ymin = estimate + qnorm(0.025)*se, 
																																													 ymax = estimate + qnorm(0.975)*se,
																																													 col=party)
	) +
	geom_point(size = 3.75,aes(shape=party)) + 
	geom_text(data = filter(coefs_for_plot,group=="Governor"),
						aes(y = estimate + qnorm(0.975)*se, x=order,label=party),hjust=-0.15) + 
	scale_y_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare",limits=c(-0.7,0.86),breaks=seq(-0.8,1,0.2)) +
	scale_x_continuous("",breaks=c(10:2),labels=c("President","Senate","House","Federal Avg","Governor","Downballot\nState Offices","State House","State Average","County")) +
	scale_color_manual(breaks = c("Democrat","Republican","Difference"),values=c("blue","red","black")) + 
	scale_shape_manual(values = c("Republican" = 19,"Democrat" = 17,"Difference" = 15)) + 
	geom_hline(yintercept = 0,size=.5,colour="black",linetype="dotted") +
	theme_bw() +
	coord_flip() + 
	theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black",
																	 face=filter(coefs_for_plot,order>2.5 & party=="Democrat")$fontface)) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=15)) + 
	theme(axis.title.x = element_text(size=20)) + 
	theme(legend.position = "none")

ggsave("Figures/coefplot_post1990_state.pdf",coef_plot_state,width=11,height=6)


## Local offices:
coef_plot_local <- ggplot(data = filter(coefs_for_plot,order<2.5), aes(y = estimate, x = order,color=party)) +
	geom_errorbar(data = filter(coefs_for_plot,order<2.5), lwd=1, width=0.0, aes(x = order, 
																																							 ymin = estimate + qnorm(0.025)*se, 
																																							 ymax = estimate + qnorm(0.975)*se,
																																							 col=party)
	) +
	geom_point(size = 3.75,aes(shape=party)) + 
	geom_text(data = filter(coefs_for_plot,group=="County"),
						aes(y = estimate + qnorm(0.975)*se, x=order,label=party),hjust=-0.15) + 
	scale_y_continuous("Effect of 1% Wage Growth Increase on Democratic Voteshare",limits=c(-5,5),breaks=seq(-5,5,1)) +
	scale_x_continuous("",breaks=c(10:1),labels=c("President","Senate","House","Federal Avg","Governor","Downballot\nState Offices","State House","State Avg","County\nLegislature","Mayor")) +
	scale_color_manual(breaks = c("Democrat","Republican","Difference"),values=c("blue","red","black")) + 
	scale_shape_manual(values = c("Republican" = 19,"Democrat" = 17,"Difference" = 15)) + 
	geom_hline(yintercept = 0,size=.5,colour="black",linetype="dotted") +
	theme_bw() +
	coord_flip() + 
	theme(axis.text.y = element_text(size=20, angle = 0, hjust = 1, color="black")) +  
	# theme(axis.title.y = element_blank()) +
	theme(axis.text.x = element_text(size=15)) + 
	theme(axis.title.x = element_text(size=20)) + 
	theme(legend.position = "none")

ggsave("Figures/coefplot_post1990_local.pdf",coef_plot_local,width=11,height=3)

